linux尋找命令

來源:互聯網
上載者:User

標籤:des   style   color   os   使用   ar   檔案   資料   cti   

1、which
文法:
[[email protected] ZS]#which 可執行檔名稱
例如:
[[email protected] ZS]#which passwd
/usr/bin/passwd
which是通過PATH環境變數到該路徑內尋找可執行檔,所以基本的功能是尋找可執行檔

2、whereis
文法:
[[email protected] ZS]#whereis [-bmsu] 檔案或者目錄名稱
參數說 明:
-b : 只找二進位檔案
-m: 只找在說明檔案manual路徑下的檔案
-s : 只找source源檔案
-u : 沒有說明文檔的檔案
例如:
[[email protected] ZS]#whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
將和passwd檔案相關的檔案都尋找出來

[[email protected] ZS]#whereis -b passwd
passwd: /usr/bin/passwd /etc/passwd
只將二進位檔案 尋找出來

和find相比,whereis尋找的速度非常快,這是因為linux系統會將系統內的所有檔案都記錄在一個資料庫檔案中,當使用whereis和下面即將介紹的locate時,會從資料庫中尋找資料,而不是像find命令那樣,通過遍曆硬碟來尋找,效率自然會很高。
但是該資料庫檔案並不是即時更新,預設情況下時一星期更新一次,因此,我們在用whereis和locate 尋找檔案時,有時會找到已經被刪除的資料,或者剛剛建立檔案,卻無法尋找到,原因就是因為資料庫檔案沒有被更新。

3、 locate
文法: 
[[email protected] ZS]# locate 檔案或者目錄名稱
例 如: 
[[email protected] ZS]# locate passwd

/etc/passwd
/etc/passwd-
/etc/dovecot/conf.d/auth-passwdfile.conf.ext
/etc/pam.d/passwd
/etc/security/opasswd
…………

4、 find
文法: 
[[email protected] ZS]# find 路徑 參數
參數說明:
時間尋找參數:
-atime n :將n*24小時記憶體取過的的檔案列出來
-ctime n :將n*24小時內改變、新增的檔案或者目錄列出來
-mtime n :將n*24小時內修改過的檔案或者目錄列出來
-newer file :把比file還要新的檔案列出來
名稱尋找參數:
-gid n       :尋找群組ID為n的檔案
-group name  :尋找群組名稱為name的檔案
-uid n       :尋找擁有者ID為n的檔案
-user name   :尋找使用者者名稱為name的檔案
-name file   :尋找檔案名稱為file的檔案(可以使用萬用字元)
例如:
[[email protected] ZS]#find / -name ZS 
/root/Desktop/ZS

[[email protected] ZS]#find / -name ‘*ZS*‘ 
/root/Desktop/ZS
/root/Desktop/ZS/ruby-1.9.3-p547/.ext/rdoc/Zlib/ZStream
/root/Desktop/ZS/ruby-1.9.3-p547/.ext/rdoc/Zlib/ZStream/cdesc-ZStream.ri
/usr/local/share/ri/1.9.1/system/Zlib/ZStream
/usr/local/share/ri/1.9.1/system/Zlib/ZStream/cdesc-ZStream.ri

 

當我們用whereis和locate無法尋找到我們需要的檔案時,可以使用find,但是find是在硬碟上遍曆查 找,因此非常消耗硬碟的資源,而且效率也非常低,因此建議大家優先使用whereis和locate。
locate 是在資料庫裡尋找,資料庫大至每天更新一次。
whereis 可以找到可執行命令和man page
find 就是根據條件尋找檔案。
which 可以找到可執行檔和別名(alias)

linux尋找命令

相關文章

聯繫我們

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