Linux中find遞迴尋找並列出所有(全部)隱藏檔案

來源:互聯網
上載者:User

我們可以在Linux 或者 Unix 系統上使用 find 命令去查詢所有(全部)隱藏檔案
文法:  在linux / Unix 上遞迴尋找並列出所有(全部)隱藏檔案
基本文法如下:
[root@dabu.info ~]#find  /要尋找的文/件/夾/  -name  ".*"  -print 
解釋:
1. ".*" 表示要尋找的檔案名稱。因為linux / Unix 的隱藏檔案和檔案夾名是以 “ . ”開頭的。而*表示萬用字元,意思是尋找所有檔案名稱和檔案夾名中,以 "." 開始檔案和檔案夾。
2.-print 表示列印尋找的結果。與 -ls 功能相同
或者
[root@dabu.info ~]#find   /要尋找的文/件/夾/   -name  ".*"  -ls
或者只搜尋隱藏的檔案:
[root@dabu.info ~]#find  /要尋找的文/件/夾/   -type  f   -iname  ".*"  -ls
或者只搜尋隱藏的檔案夾:
[root@dabu.info ~]#find  /要尋找的文/件/夾/     -type  d  -iname  ".*"   -ls
解釋:
-type :指定要搜尋的檔案的類型,是檔案夾還是檔案等,要與f或d一起用
f :意思代表檔案,檔案的英文是file。
d : 就代表檔案夾,檔案夾的英文是 directory
-iname :表示匹配檔案名稱的時候,忽略大小寫。如,尋找“fo*” ,則 “foo” ,"fOO"都會匹配。
或者
[root@dabu.info ~]#find  /要尋找的文/件/夾/     -path  '*/.*'   -print
[root@dabu.info ~]#find  /要尋找的文/件/夾/     -path  '*/.*'   -ls
關於-path參數的解釋,見另外一篇文章《find命令中-path 參數的作用(意思)解釋》
 
在下面的例子中,尋找 $HOME 下的所有隱藏的檔案與檔案夾($HOME就是使用者的家目錄,你可以用 (echo $HOME 命令來查看,你就明白意思了)
[root@dabu.info ~]#find   $HOME   -name   ".*"  -ls  #已經遞迴查詢了
輸出如下:
553607    4 -rw-r--r--   1 root     root          100 Sep 22  2004 ./.cshrc
6553664    4 -rw-------   1 root     root         1024 Nov 17 04:40 ./.rnd
6553604    4 -rw-r--r--   1 root     root           18 May 20  2009 ./.bash_logout
6553665    4 drwx------   2 root     root         4096 Dec 18  2012 ./.gnupg
6553671    0 -rw-------   1 root     root            0 Dec 18  2012 ./.gnupg/secring.gpg
6553669    0 -rw-------   1 root     root            0 Dec 18  2012 ./.gnupg/pubring.gpg~
6553673    4 -rw-------   1 root     root          899 Dec 18  2012 ./.gnupg/pubring.gpg
6553667    8 -rw-------   1 root     root         7856 Dec 18  2012 ./.gnupg/gpg.conf
6553668    4 -rw-------   1 root     root         1200 Dec 18  2012 ./.gnupg/trustdb.gpg
6553602   20 -rw-------   1 root     root        17462 Apr  7 10:55 ./.bash_history
6553610    4 drwx------   3 root     root         4096 Jan 16  2013 ./.config
6553660    4 drwx------   2 root     root         4096 Jan 16  2013 ./.config/htop
6553681    4 -rw-r--r--   1 root     root          597 Apr 11  2013 ./.config/htop/htoprc
6553723   12 -rw-------   1 root     root         9629 Mar 30 23:56 ./.viminfo
6553615    4 drwxr-xr-x   3 root     root         4096 Nov 29  2012 ./.original-configs
為了將結果存放到文字檔foo.txt中,使用輸出重新導向,命令如下:
[root@dabu.info ~]#find  $HOME   -name ".*"  -ls   >  foo.txt
[root@dabu.info ~]#cat foo.txt   #  查看foo.txt檔案的內容,即find命令的運行結果
下面假設我要查看 /home/www/  下的隱藏檔案與檔案夾,並將結果儲存至foo.txt。使用下面的命令:
[root@dabu.info ~]#find  /home/www/   -name  ".*"  -ls  > foo.txt

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.