Linux基本命令練習 9 grep

2021-07-17 04:57:45 字數 1252 閱讀 4046

find命令是根據檔案的屬性進行查詢,如檔名,檔案大小,所有者,所屬組等。

grep命令是根據檔案的內容進行查詢,會對檔案的每一行按照給定的模式(pattern)進行匹配查詢。

options

[root@muban data]# cat iantest1.txt 

1ian aaa

2ian aaa

3ian aaa

#把包含字串"1"的一整行全列印出來

[root@muban data]# grep "1" iantest1.txt

1ian aaa

#只列印包含的內容字串"1"

[root@muban data]# grep -o "1" iantest1.txt

1[root@muban data]# grep -v "1" iantest1.txt

2ian aaa

3ian aaa

-e 可以同時過濾多個匹配文字

[root@muban data]# grep -e "3306|1521" /etc/services

[root@muban data]# egrep "3306|1521" /etc/services

#這兩條命令結果相同 grep-e相當於egrep

#在檔案中找到包含3306或者包含1521的行

-n 與–color=auto

[root@ianlinux data]# alias grep='grep --color=auto'

[root@ianlinux data]# grep -n "3306" /etc/services

416,417都是行號

Linux基本命令練習(3)

參考實驗樓課程linux 命令例項練習 which 命令的作用是,在 path 變數指定的路徑中搜尋可執行檔案的所在位置。它一般用來確認系統中是否安裝了指定的軟體。which 可執行檔名稱 which gcc 確認是否安裝了 gcc返回 gcc安裝路徑 echo shell 命令檢視當前使用的 sh...

Linux基本命令練習(2)

1.已知 tmp目錄下已經存在test.txt檔案,如何執行命令才能把 mnt test.txt拷貝到 tmp下覆蓋掉 tmp test.txt,而讓linux系統不提示是否覆蓋 root許可權下 兩種方法 一種是在cp命令前加乙個 另一種是用cp命令的全路徑 為什麼直接用cp,會提示是否覆蓋呢?這...

Linux基本命令練習 3

1.把當前目錄及其子目錄下所有以副檔名.sh結尾的檔案中包含.hostlist.txt的字串全部替換為.idctest iplist。find type f name sh xargs sed i s hostlist.txt idctest iplist g xargs 用於把find ls的輸出...