Linux學習筆記--搜尋命令__Linux

來源:互聯網
上載者:User

#whereis  [選項]  [命令名] 功能:搜尋命令所在路徑及其協助文檔位置

選項:-b  只擷取命令位置;  -m  只擷取協助文檔位置



#which  [命令名]

功能:搜尋命令所在路徑及別名



#locate  [檔案名稱]

功能:在後台資料庫“/var/lib/mlocate”中,按照檔案名稱搜尋

注意:1、locate為包含匹配;

          2、對應的後台資料庫不是即時更新的,所以最近產生的檔案無法搜尋到;

          3、#updatedb命令可以即時更新資料庫



whereis  which  locate  這三個命令,遵循設定檔 /etc/updatedb.conf 指定的搜尋規則:



#find  [搜尋範圍]  [搜尋條件]

功能:在指定範圍內,搜尋符合指定條件的檔案

選項: -name  按照檔案名稱搜尋(完全符合);

           -iname  按照檔案名稱搜尋(完全符合),不區分大小寫;

           -user  按照檔案所有者搜尋;

           -nouser  搜尋沒有所有者的檔案

           #find  /var/log/  -mtime  +10    搜尋log目錄下10天前最後修改內容的檔案

           #find  /var/log/  -ctime  -10    搜尋log目錄下10天內最後改變屬性的檔案

           #find  /var/log/  -atime  10    搜尋log目錄下10天當天最後發生訪問的檔案

           #find  /var/log/  -size  25k    搜尋log目錄下檔案大小等於25k的檔案

           #find  /var/log/  -size  +25M    搜尋log目錄下檔案大小大於25M的檔案

           #find  /var/log/  -size  -25k    搜尋log目錄下檔案大小小於25k的檔案    ----k小寫,M大寫,預設單位為資料區塊(512位元組)

           #find  .  -inum  262422    搜尋目前的目錄下 i節點 是 262422 的檔案

           #find  /var/log/  \(  -size  +5k  -a  -size  -100k  \)    

                                                 搜尋log目錄下檔案大小大於5k小於100k的檔案

           #find  /var/log/  \(  -name  "*.log"  -a  \(  -mtime  -1  -o  -mtime  +5  \)  \)    ----   -a  "and"  ;   -o  "or"

                                                 搜尋log目錄下檔案名稱以".log"結尾,且最後修改時間不在1至5天範圍內的檔案

           #find  ..  -name  "file*"  -exec  ls  -ilh  {}  \;   

                                                 搜尋上一級目錄下檔案名稱以"file"開頭的檔案,並顯示檔案的詳細資料

           #find  /var/log/  -name  "an*"  -o  -name  "*.log"  -ok  rm  -rf {}  \;

                                           搜尋log目錄下以"an"開頭或者以".log"結尾的檔案,對其執行刪除操作,並在刪除前詢問


#grep  [選項]  [字串]  [檔案名稱]

功能:在指定檔案中搜尋指定的字串,並列印包含該字串的行(包含匹配)

選項:-i  忽略大小寫;    -v  排除指定字串





聯繫我們

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