linux基礎命令(22) find 命令的參數詳解

來源:互聯網
上載者:User

find一些常用參數的一些常用執行個體和一些具體用法和注意事項。

1.使用name選項:

檔案名稱選項是find命令最常用 的選項,要麼單獨使用該選項,要麼和其他選項一起使用。 可以使用某種檔案名稱模式來匹配檔案,記住要用引號將檔案名稱模式 引起來。  不管當前路徑是什麼,如果想要在自己的根目錄$HOME中尋找檔案名稱符合*.log的檔案,使用~作為 'pathname'參數,波浪號~代表了你的$HOME目錄。

find ~ -name "*.log" -print

想要在當 前目錄及子目錄中尋找所有的‘ *.log‘檔案,可以用:

find . -name "*.log" -print

想要的當前 目錄及子目錄中尋找檔案名稱以一個大寫字母開頭的檔案,可以用:

find . -name "[A-Z]*" -print

想 要在/etc目錄中尋找檔案名稱以host開頭的檔案,可以用:

find /etc -name "host*" -print

想要尋找 $HOME目錄中的檔案,可以用:

find ~ -name "*" -print 或find . -print

要想讓系統高負荷運行, 就從根目錄開始尋找所有的檔案。

find / -name "*" -print

如果想在目前的目錄尋找檔案名稱以一個個 小寫字母開頭,最後是4到9加上.log結束的檔案:

命令:

find . -name "[a-z]*[4-9].log" - print

輸出:

[root@localhost test]# ll

總計 316

-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log

-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log

-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log

-rw-r--r-- 1 root root      0 11-13 06:06 log2015.log

drwxr-xr-x 6 root root   4096 10-27 01:58 scf

drwxrwxr-x 2 root root   4096 11-13 06:08 test3

drwxrwxr-x 2 root root   4096 11-13 05:50 test4

[root@localhost test]# find . -name "[a-z]*[4-9].log" - print

./log2014.log

./log2015.log

./test4/log2014.log

[root@localhost test]#

2.用 perm選項:

按照檔案許可權模式用-perm選項,按檔案許可權模式來尋找檔案的話。最好使用八進位的許可權標記法。

如 在目前的目錄下尋找檔案許可權位為755的檔案,即檔案屬主可以讀、寫、執行,其他使用者可以讀、執行的檔案,可以用:

[root@localhost test]# find . -perm 755 - print

.

./scf

./scf/lib

./scf/service

./scf/service/deploy

./scf/service/dep loy/product

./scf/service/deploy/info

./scf/doc

./scf/bin

[root@localhost test]#

還有一種表達方法:在八位元字前面要加一個橫杠-,表示都匹配,如-007就相當於777,-005相當於555,

命令:

find . -perm -005

輸出:

[root@localhost test]# ll

總計 316

-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log

-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log

-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log

-rw-r--r-- 1 root root      0 11-13 06:06 log2015.log

drwxr-xr-x 6 root root   4096 10-27 01:58 scf

drwxrwxr-x 2 root root   4096 11-13 06:08 test3

drwxrwxr-x 2 root root   4096 11-13 05:50 test4

[root@localhost test]# find . -perm - 005

.

./test4

./scf

./scf/lib

./scf/service

./scf/service/deploy

./scf /service/deploy/product

./scf/service/deploy/info

./scf/doc

./scf/bin

./test3

[root@localhost test]#

聯繫我們

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