歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 每天一個Linux命令(17)whereis命令

每天一個Linux命令(17)whereis命令

日期:2017/3/3 12:48:50   编辑:Linux技術

whereis命令只能用於程序名的搜索,而且只搜索二進制文件(參數-b)、man說明文件(參數-m)和源代碼文件(參數-s)。如果省略參數,則返回所有信息。 [b] (1)用法:[/b]

[b] 用法: whereis [-bmsu] [BMS 目錄名 -f ] 文件名[/b][b] (2)功能:[/b]

[b] 功能: [/b]用來定位指令的二進制程序、源代碼文件和man手冊頁等相關文件的路徑。[b] (3)選項參數:[/b]

1) -b:     只查找二進制文件 2) -B<目錄>:     只在設置的目錄下查找二進制文件

3) -f:     不顯示文件名前的路徑名稱 4) -m:     只查找說明文件

5) -M<目錄>:     只在設置的目錄下查找說明文件 6) -s:            只查找原始代碼文件

  7) -S<目錄>:         只在設置的目錄下查找原始代碼文件  8) -u:             查找不包含指定類型的文件

[b] (4)實例:[/b] 1)[sunjimeng@localhost ~]$ whereis cd 查找與cd命令有關的所有文件,包括二進制,man說明文件,源代碼文件。

[sunjimeng@localhost ~]$ whereis cd
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
[sunjimeng@localhost ~]$ whereis pwd
pwd: /usr/bin/pwd /usr/include/pwd.h /usr/share/man/man1/pwd.1.gz /usr/share/man/man1p/pwd.1p.gz
2)[sunjimeng@localhost ~]$ whereis -b|-s|-m cd

[sunjimeng@localhost ~]$ whereis -b cd
cd: /usr/bin/cd
[sunjimeng@localhost ~]$ whereis -s cd
cd:[sunjimeng@localhost ~]$ whereis -m cd
cd: /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
3)[sunjimeng@localhost ~]$ whereis -f cd

[sunjimeng@localhost ~]$ whereis -f cd                         //好像沒什麼區別啊
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
[sunjimeng@localhost ~]$ whereis cd
cd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
4)[sunjimeng@localhost ~]$ whereis whereis

[sunjimeng@localhost ~]$ whereis whereis
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz
[sunjimeng@localhost ~]$ whereis -b whereis
whereis: /usr/bin/whereis
[sunjimeng@localhost ~]$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz
[sunjimeng@localhost ~]$ whereis -s whereis
[b] (5)其他:[/b]

說明:

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

Copyright © Linux教程網 All Rights Reserved