Linux尋找檔案

來源:互聯網
上載者:User

標籤:c   class   blog   code   java   tar   

which 可以尋找可執行檔的位置

?
1 2 [email protected]:~$ which ping /bin/ping

 

whereis

whereis -m 可查詢到命令的協助文檔在什麼地方

?
1 2 3 4 [email protected]:~$ whereis -m ls ls: /usr/share/man/man1/ls.1.gz [email protected]:~$ whereis -m pwd pwd: /usr/share/man/man1/pwd.1.gz

 

?
1 2 [email protected]:~$ whereis pwd pwd: /bin/pwd /usr/include/pwd.h /usr/share/man/man1/pwd.1.gz

 輸出資訊有三條
1.命令本身所在目錄
2.其源檔案所在目錄
3.其協助文檔所在目錄

locate 基於本機電腦資料庫(電腦磁碟資訊),速度比find快些。locate一般是在晚上更新資料庫,但是也可以自己手動更新

?
1 [email protected]:~# sudo updatedb
?
1 2 3 4 5 6 7 8 [email protected]:~/test# ls 1.txt  2.txt  aa.tar.gz  ab.tar.bz2  ac.tar  ac.tar.bz2  ac.tar.gz [email protected]:~/test# locate aa.tar.gz /root/test/aa.tar.gz [email protected]:~/test# cd /tmp [email protected]:/tmp# locate aa.tar.gz /root/test/aa.tar.gz [email protected]:/tmp#

 

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 建立一個新檔案,用locate試試~ [email protected]:~/test# touch aobama [email protected]:~/test# ed aobama 0 a 我是新建立的檔案, 看下locate命令能找到我麼~ . w 63 q [email protected]:~/test# locate aobama [email protected]:~/test# 結果找不到~

 

?
1 2 3 4 5 更新資料庫後看下: @IdeaPad:~/test# sudo updatedb [email protected]:~/test# locate aobama /root/test/aobama [email protected]:~/test#

 

find 命令 全盤掃描,類似windows的尋找;速度比較慢

find可以基於檔案名稱尋找

?
1 2 3 4 5 6 [email protected]:~# find ./ -name ‘te*‘ ./test [email protected]:~# find ./ -name ‘1*‘ ./test/1.txt ./1.txt [email protected]:~#

 

聯繫我們

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