您現在的位置是:首頁 > 運動

grep:每週一個linux命令

由 freedom47 發表于 運動2022-04-17
簡介txt 檔名-c統計符合字串條件的行數grep、cat、管道符配合使用cat test

grep命令怎麼用

每週一個linux命令(grep)

grep

每週一個linux命令

基礎環境

grep:每週一個linux命令

grep 命令介紹

grep 查詢檔案裡符合條件的字串,常與管道符

|

cat

ps

一起使用;主要用於查詢檔案中符合條件的字串、統計檔案中符合條件的字串行數、grep 不顯示自身程序

grep 常用命令引數

-c

:統計符合字串條件的行數

-v

:顯示不包括文字的所有資訊

grep 常用命令

過濾test。txt檔案中hello內容

grep hello test。txt

grep:每週一個linux命令

說明:

hello 關鍵字

test。txt 檔名

統計test。txt中hello內容的行數

grep -c hello test。txt

grep:每週一個linux命令

說明:

hello 關鍵字

test。txt 檔名

-c

統計符合字串條件的行數

grep、cat、管道符配合使用

cat test。txt |grep hello

grep:每週一個linux命令

說明:

過濾test。txt檔案中hello內容

hello 關鍵字

test。txt 檔名

cat

列印檔案內容

|

管道符,將一個命令的輸出作為另外一個命令的輸入

grep、ps、管道符配合使用

ps -ef|grep ssh

grep:每週一個linux命令

說明:

過濾ssh程序資訊

ps

列印程序資訊

ssh

過濾關鍵字

|

管道符,將一個命令的輸出作為另外一個命令的輸入

去掉grep自身程序

ps -ef|grep ssh|grep -v grep

grep:每週一個linux命令

說明:

過濾ssh程序資訊,並去除最後一行的grep資訊

ps

列印程序資訊

ssh

過濾關鍵字

|

管道符,將一個命令的輸出作為另外一個命令的輸入

-v

顯示排除grep關鍵字的所有資訊

推薦文章