linux檔案搜尋

來源:互聯網
上載者:User

 

1、locate  --->檔案尋找事先產生的資料庫,模糊尋找,updatedb更新locate資料庫
     -i  : 忽略檔案名稱的大小寫
     -n  : 只顯示前n行  eg:locate -n 3 passwd
   2、find    ---->即時尋找,精確匹配檔案名稱
         find [DIR  ...] [CRIERIA] [ACTION...]
           DIR:/root /home .. (預設目前的目錄)
           ACTION;
               -print (預設)
               -ls 
               -ok   COMMAND  互動式執行命令
               -exec  COMMAND  非互動式執行命令
               xargs     從標準輸出中執行和建立命令
                 eg;find /root -name "[[:alpha:]][[:digit:]]" -exec mv {} {} \;  //{}代表前面尋找的結果,後面必須用\;結尾
                     find /root -name "[[:alpha:]][[:digit:]]"  | xargs chmod 755
            CRIERIA:
               -name :精確到指定的檔案名稱
               -iname: 根據檔案名稱尋找,但不區分大小寫
               -user :根據屬主尋找
               -group:根據屬組尋找
               -uid  :根據uid尋找
               -gid  :根據gid尋找
               在指定時間段裡尋找:
               -atime: [+/-]N (access time)  :+-表示---(+)----N---(-)----currentday
                       eg:find -atime -3 -exec ls -l {} \;
               -mtime:    (modification time)同上
               -ctime    (change time)    同上
               
               -amin   以分種為單位,同上
               -mmin
               -cmin
               
               -anewer  a.txt  比a.txt更近的訪問
                       eg:  find -anewer sh01.sh -exec ls -l {} \;
               -newer            相當於modification time
               -cnewer           相當於change time
               -type:按照類型尋找
                          d(目錄),l(連結檔案),f(普通檔案),s(套接檔案),
                          b(塊裝置),c(字元裝置),p(命令管道檔案)
                       eg:find /var  -type l  -exec ls -l {} \;
               -size: 按照大小尋找
                 [+/-]N
               -perm [+/-]mode 根據許可權尋找
                      mode 755
                      -222 每一類使用者都要匹配
                      eg:find /tmp/myscrip  -perm -001
                      /222 某一個使用者只要有一類許可權的即可
               -nouser :沒有使用者
                        eg: find / -nouser  查看沒有使用者名稱的檔案,一般這種檔案有一定的危險性
               -nogroup:沒有組的
               
           
               尋找條件串連:
                      -a        :&& 通常可以省略
                      eg: find -user  root -type f -exec ls -dl {} \;
                      -o        :||
                      eg:find -user named -o -type d  -exec ls -ld {} \;
                      -not or ! :!
                      eg:find -not \( -type d -a -user root \) -exec ls -ld {} \;
               
               
               -ls -l `find / -name passwd`
               
               檔案名稱通配:*任意一個字元,?單個字元,[]
                eg: find /tmp -name a* //尋找以a開頭的檔案

本文出自 “IT夢-齊-分享” 部落格

 

聯繫我們

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