CentOS 6.5 用 find 搜尋指定路徑下的檔案 – 筆記

2014-08-31 CentOS

find 是 Linux 常用的搜尋指令,此篇紀錄 find 的常用用法

 

 

用 find 通常用來搜尋某個路徑下的檔案,加入 grep 後也可以搜尋檔案內的文字內容

find "path name" -name "file name" -exec grep -H "search content" {} \;

 

 

範例

參數 -name 

搜尋在 /home 內所有 *.css 檔案

$ find /home -name "*.css"

 

搜尋在 /home 內所有 *.css 檔案內容中有 site-title 的文字

$ find /home -name "*.css" -exec grep -H "site-title" {} \;

 

搜尋 /home 內以 A-Z 大寫字首開頭的檔案

$ find /home -name "[A-Z]*"

 

搜尋 /home 內以 A-Z 大寫字首,並且字尾為 0-9 的檔案

find /home -name "[a-z]*[0-9]"

 

 

參數 -perm

perm 可以用來搜尋指定權限的檔案,方便用來找有權限問題的檔案

搜尋 /home 內權限 755 的檔案

$ find /home -perm 755

 

 

 

給 Mr. 沙先生一點建議

彙整

分類

展開全部 | 收合全部

License

訂閱 Mr. 沙先生 的文章

輸入你的 email 用於訂閱