linux/unix shell的find用法小練

來源:互聯網
上載者:User

linux/unix shell的find用法小練 好久之前的筆記了,搬出來和大家共用:參數解釋:find用來查詢某個目錄下的檔案幾種常用的參數如下-path 後面跟著要查詢的路徑  www.2cto.com  -prune 表示不再指定目錄下查詢,如果同時使用-depth,那麼-prune命令將會被忽略-name 要查詢的檔案名稱,可以使用Regex來查詢-mtime 查詢近n天更改過的檔案+表示大於n,-n表示n天以內-另外還有-atime和-ctime用法類似 -newer file1 ! -newer file2 表示查詢比file1新,比file2舊的檔案-exec 表示對查詢出來的檔案進行某些命令操作,如 -exec ls -l {} \;-type 要查詢的檔案類型! -type d 表示除了類型為目錄的-size 指定大小的檔案+10c或-10c:大於10個位元組的,或者小於10個位元組的示範:[oracle@localhost testDir]$ cat find.sh echo "prune:" >> find.outfind . -path "./folder" -prune -o -name "file*" >> find.outecho "-name:" >> find.outfind . -name "[a-z][a-z]*" >> find.outecho "-mtime: +3" >> find.outfind . -mtime +3 >> find.outecho "-mtime: -3" >> find.outfind . -mtime -3 >> find.outecho "find newer then 1 and older then 2 files:">> find.outfind . -newer "test1.sh" ! -newer "test2.sh" -exec ls -l {} \; >> find.outecho "-type:" >> find.outfind . -type d >> find.outecho "except type:" >> find.outfind . ! -type d >> find.outecho "-size +10c :" >> find.outfind . -size +10c >> find.outecho "-size -10c :" >> find.outfind . -size -10c >> find.out輸出結果:[oracle@localhost testDir]$ cat find.out prune:./folder-name:./blank_file./find.sh./shelltest.sh./folder./folder/file1./test1.log./test1.sh./test2.sh./main.sh./find.out-mtime: +3./find.sh./shelltest.sh./folder./folder/file1./test1.sh./test2.sh./main.sh-mtime: -3../blank_file./test1.log./find.outfind newer then 1 and older then 2 files:-rwxr-xr-x 1 oracle oinstall 100 Nov 10 23:08 ./test2.sh-rwxr-xr-x 1 oracle oinstall 26 Nov 10 22:30 ./main.sh-type:../folderexcept type:./blank_file./find.sh./shelltest.sh./folder/file1./test1.log./test1.sh./test2.sh./main.sh./find.out-size +10c :../blank_file./find.sh./shelltest.sh./folder./test1.log./test1.sh./test2.sh./main.sh./find.out-size -10c :./folder/file1
 

聯繫我們

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