linux grep搜尋檔案中的字串

2021-09-30 09:17:46 字數 780 閱讀 7191

[root@localhost ~]# grep 'root' /etc/group

root:x:0:root

bin:x:1:root,bin,daemon

[root@localhost ~]# grep 'root' /etc/group /etc/my.cnf

/etc/group:root:x:0:root

/etc/my.cnf:user = root

查詢當前目錄下以及下轄子目錄下所有包含str字串的檔案,會列出檔名.以及該行的內容.以及行號 

-n是列印行號,-r是在子目錄也要查詢

grep -n "str" -r ./

用 -i 搜尋的時候可以忽略大小寫

所有的子目錄下面執行相應的查詢,利用 -r 來完成

用-l是列印所有的結果

grep -ril 'str' ./

find 是查詢檔案的常用命令

查詢在 /etc 目錄下所有檔名中含有 mail 的檔案

[root@localhost ]# find /etc/ -name '*mail*'

/etc/mail.rc

/etc/rc.d/rc5.d/k30sendmail

/etc/rc.d/rc4.d/k30sendmail

查詢檔案大小超過指定值的檔案

[root@localhost ]# find ./ -type f -size +100m

./test.sql

最近幾天被修改過的檔案

find . -mtime -2

linux grep搜尋檔案中的字串

root localhost grep root etc group root x 0 root bin x 1 root,bin,daemon root localhost grep root etc group etc my.cnf etc group root x 0 root etc my....

linux grep搜尋檔案中的字串

root localhost grep root etc group root x 0 root bin x 1 root,bin,daemon root localhost grep root etc group etc my.cnf etc group root x 0 root etc my....

linux grep 指定檔案字尾名搜尋

在安裝的solr裡找一些單詞,使用grep 寫法如下 pwd opt solr solr hbase f trademark info index tbs conf grep hbase f trademark info index tbs 表示在當前目錄下所有檔案找單詞 hbase f trade...