linux中find命令中-path 參數的作用中文介紹

來源:互聯網
上載者:User

find命令中-path 參數的作用(意思)解釋
-path pattern
    File name matches shell pattern pattern. The metacharacters do not treat /' or .' specially; so, for example,
    find . -path './sr*sc'
    will print an entry for a directory called './src/misc' (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory `src/emacs' and all files and directories under it, and print the names of the other files found, do something like this:
    find . -path './src/emacs' -prune -o -print
意思就是說,find命令中用了-path 參數,則檔案名稱是匹配shell萬用字元模式。這時候,元字元不能識別 '/ '  和 ' . '  。舉個例子
假設/root 目錄下有四個檔案,其絕對路徑分別為:
/root/src/misc
/root/src/test/misc
/root/src1misc
/root/test/src/misc
這時候輸入下面的命令:
[root@dabu.info ~]# cd  /root
[root@dabu.info ~]#find . -path   './sr*sc' 
./src1misc
./src/misc
./src/test/misc  
命令運行輸出的結果不是檔案名稱,而是檔案的路徑
可見,檔案夾符號/  在此時也可以用 * 萬用字元匹配,而且 * 是可以匹配n多個字元。上面的命令列的意思是是在目前的目錄下及子目錄遞迴尋找檔案路徑 匹配的檔案,所以輸出的是檔案的路徑。
因為是'./sr*sc'  ,所以 /root/test/src/misc這個檔案不匹配,因為  ./   代表目前的目錄 (即/root) ,而 /root/test/src/misc不符合 ./sr的格式。
但是稍微改一下,如下:
[root@dabu.info ~]#find  .  -path  '*/sr*sc*'
./src1misc
./src/misc
./src/test/misc 
./test/src/misc 
解釋:因為" * " 可以匹配 "." 和  "  / ", 我們將上面的'*/sr*sc*'  改為  '*sr*sc*'   。結果也是一樣的。
注意:也可以直接用絕對路徑
[root@dabu.info ~]#find /root   -path  '*/sr*sc*'
而
[root@dabu.info ~]#find  /root   -path  '/root/sr*sc*'
/root/src1misc
/root/src/misc
/root/src/test/misc
此時, /root/test/src/misc 是不符的'/root/sr*sc*'的格式的。
所以Linux / Unix:遞迴尋找並列出所有(全部)隱藏檔案的方法可以如下:
[root@dabu.info ~]#find  /要尋找的文/件/夾/     -path  '*/.*'   -print
教程完!
-path更多的是配合 -prune -o  來在操作時排除指定的檔案。這裡就不說了,大家自行百度去吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.