find命令基本使用一覽,find命令使用一覽

來源:互聯網
上載者:User

find命令基本使用一覽,find命令使用一覽
find命令相對於locate這種非即時尋找的搜尋命令,大大增加了我們搜尋的便捷度以及準確性;並且能夠方便的協助我們對大檔案、特定類型的檔案尋找與刪除,特別是有超多小碎檔案的時候,更是方便至極....根據屬主 屬組尋找

   -user username:尋找屬主是xx的檔案   -group group:尋找屬組的xx檔案   -uid useruid:尋找uid號的檔案   -gid groupid:尋找gid號的檔案   -nouser:尋找沒有屬主的檔案,即檔案存在但是 user已被刪除   -nogroup:尋找沒有屬組的檔案
根據檔案類型尋找
    -type f:普通檔案   -type d:目錄檔案   -type l:符號連結檔案   -type s:通訊端檔案   -type b:塊裝置檔案   -type c:字元裝置檔案   -type p:管道檔案
根據大小尋找
    -size +10M :大於10m的檔案    -size +10k:大於10k的檔案    -size +1G:大於1G的檔案    -size -1G:小於檔案的檔案
根據時間尋找
    一天為單位        -atime :訪問時間        -mtime :修改時間        -ctime :改變時間   以分鐘為單位:        -amin: 訪問時間
-mmin:修改時間
-cmin:改變時間
根據許可權尋找
    -perm +mode:    -perm +600:屬主屬組其他許可權 只要有一個匹配就當成功;600代表三個對象,6屬主 CentOS7上 使用 /600    -perm -600:每個對象都必須同時擁有其指定的許可權,三個對象同時成立 如:-003表示其他使用者必須有寫與執行許可權
組合條件尋找
   -a  :與   -o  :或   -not:非   !  :非
處理動作
    -print:列印到螢幕    -ls:尋找到的檔案 進行 ls    -delete:刪除尋找到的檔案    -ok command {}\; 對尋找的檔案執行由command指定的命令,互動式    -exec command {}\;同上,非互動式    {}:代表前面find找到的 檔案名稱本身    例如:    find ./ -type f -exec cp {} {}.bak \; 將尋找到的檔案都複製出一個.bak檔案
find尋找後的動作傳遞模式預設:尋找到指定類型的檔案時進行一次性傳遞xargs:xargs命令即讓find尋找的傳遞模式為 尋找一個傳遞一個到動作上,刪除較多碎檔案很好用,例如:find -type f | xargs command;相關樣本介紹:
尋找/home/test目錄下的符號*.txt的檔案find /home/test -name "*.txt" -print尋找許可權是755的find /home/test -perm 755 -print尋找屬主是test的find /home/test -user test -print尋找數組是test的find /home/test -group test -print尋找更改時間小於5天的find /home/test -mtime -5 -print尋找更改時間大於3天的find /home/test -mtime +3 -print尋找所有目錄find /home/test -type d -print尋找除了目錄的所有檔案find /home/test ! -type d -print尋找檔案find /home/test -type f -print尋找符號連結檔案find /home/test -type l -pint不包括/home/test/test/目錄下的test.shfind /home/test -name "test.sh" -prune /home/test/test -print刪除test.sh檔案find /home/test -name "test.sh" -type f -exec rm {} \;顯示以test開頭的檔案find /home/test -name "*test*" -type f -exec more {} \;

 

 

聯繫我們

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