linux命令中find, which、whereis、locate,有什麼區別?
阿新 • • 發佈:2019-01-01
whatis 用於查詢一個命令執行什麼功能,並將查詢結果列印到終端上
which 檢視可執行檔案的位置
whereis 檢視檔案的位置
man Linux提供了豐富的幫助手冊,當你需要檢視某個命令的引數時不必到處上網查詢,只要man一下即可
locate 配 合數據庫檢視檔案位置
find 實際搜尋硬碟查詢檔名稱
type 用來區分某個命令是否是shell自帶的
- whatis
whatis 用於查詢一個命令執行什麼功能,並將查詢結果列印到終端上
whatis whatis
whatis (1) - display one-line manual page descr.. .
whatis which
which (1) - locate a command
whatis whereis
whereis (1) - locate the binary, source, and man...
whatis man
man (1) - an interface to the on-line refere...
man (7) - macros to format man pages
whatis locate
locate (1) - find files by name
whatis find
find (1) - search for files in a directory hi...
whatis type
type: nothing appropriate.
whatis who
who (1) - show who is logged on
whatis top
top (1) - display Linux processes
- which
which命令是查詢這個命令是否存在系統中,以及命令存放的位置在哪兒.
which whatis
/usr/bin/whatis
which which
/usr/bin/which
which whereis
/usr/bin/whereis
which man
/usr/bin/man
which locate
/usr/bin/locate
which find
/usr/bin/find
which type
which ls
/bin/ls
which cat
/bin/cat
which top
/usr/bin/top
which python
/usr/bin/python
which python3
/usr/bin/python3
which pip
/usr/bin/pip
which mysql
/usr/bin/mysql
which mysqld
/usr/sbin/mysqld
which vim
/usr/bin/vim
which sqlite
- whereis
whereis命令只能用於搜尋程式名,而且只搜尋二進位制檔案(引數-b)、man說明檔案(引數-m)和原始碼檔案(引數-s)。如果省略引數,則返回所有資訊。
whereis whatis
whatis: /usr/bin/whatis /usr/share/man/man1/whatis.1.gz
whereis which
which: /usr/bin/which /bin/which /usr/share/man/man1/which.1.gz
whereis whereis
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz
whereis man
man: /usr/bin/man /usr/local/man /usr/share/man /usr/share/man/man1/man.1.gz /usr/share/man/man7/man.7.gz
whereis locate
locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz
whereis find
find: /usr/bin/find /usr/share/man/man1/find.1.gz /usr/share/info/find.info.gz
whereis type
type:
whereis vim
vim: /usr/bin/vim.basic /usr/bin/vim /usr/bin/vim.tiny /etc/vim /usr/share/vim /usr/share/man/man1/vim.1.gz
whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
whereis mysqld -b
mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz
whereis mysqld
mysqld: /usr/sbin/mysqld /usr/share/man/man8/mysqld.8.gz
whereis python
python: /usr/bin/python /usr/bin/python3.5m /usr/bin/python3.5 /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python3.5 /usr/lib/python2.7 /etc/python /etc/python3.5 /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python2.7 /usr/include/python3.5m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
whereis python2
python2: /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /etc/python2.7 /usr/local/lib/python2.7 /usr/include/python2.7 /usr/share/man/man1/python2.1.gz
whereis python3
python3: /usr/bin/python3.5m /usr/bin/python3 /usr/bin/python3.5 /usr/lib/python3 /usr/lib/python3.5 /etc/python3 /etc/python3.5 /usr/local/lib/python3.5 /usr/include/python3.5m /usr/share/python3 /usr/share/man/man1/python3.1.gz
- man
man 是 Linux提供了豐富的幫助手冊,當你需要檢視某個命令的引數時不必到處上
man whatis
output a lot
man which
output a lot
man whereis
output a lot
man man
output a lot
man locate
output a lot
man find
output a lot
man type
No manual entry for type
- locate
locate命令不是實時查詢,所以查詢的結果不精確,但查詢速度很快。因為它查詢的不是目錄,而是一個數據庫(/var/lib/locatedb),這個資料庫中含有本地所有檔案資訊。Linux系統自動建立這個資料庫,並且每天自動更新一次,所以使用locate命令查不到最新變動過的檔案。為了避免這種情況,可以在使用locate之前,先使用updatedb命令,手動更新資料庫。
sudo updatedb
locate whatis
output a lot
locate which
output a lot
locate whereis
/usr/bin/whereis
/usr/share/bash-completion/completions/whereis
/usr/share/man/man1/whereis.1.gz
locate man
output a lot
locate locate
output a lot
locate find
output a lot
locate type
output a lot
locate passwd
will output a lot
locate -n 5 passwd
/etc/passwd
/etc/passwd-
/etc/cron.daily/passwd
/etc/init/passwd.conf
/etc/pam.d/chpasswd
locate vim
output a lot
- find
find是最常用和最強大的查詢命令。它能做到實時查詢,精確查詢,但速度慢。
find的使用格式如下:
#find [指定目錄] [指定條件] [指定動作]
指定目錄:是指所要搜尋的目錄和其子目錄。如果不指定,則預設為當前目錄。
指定條件:是指所要搜尋的檔案的特點。
指定動作:是指對搜尋的結果如何處理。
常見選項:
-name 根據檔名稱查詢(嚴格區分大小寫,如果檔名中間有空格,則必須把檔名用雙引號引起來)
-iname 根據檔名查詢(不區分大小寫)
-regex “PATTERN” 正則表示式匹配
-user 根據檔案屬主進行查詢
-group 根據檔案屬組進行查詢
-uid 根據檔案的uid查詢
-gid 根據使用者的gid查詢
-nouser 檢視所有的沒有屬主的檔案
-nogroup 檢視所有的沒有屬組的檔案
find whatis
find: ‘whatis’: No such file or directory
find which
find: ‘which’: No such file or directory
find whereis
find: ‘whereis’: No such file or directory
find man
find: ‘man’: No such file or directory
find locate
find: ‘locate’: No such file or directory
find find
find: ‘find’: No such file or directory
find type
find: ‘type’: No such file or directory
- type
type命令用來區分某個命令到底是由shell自帶的,還是由shell外部的獨立二進位制檔案提供的。如果一個命令是外部命令,那麼使用-p引數,會顯示該命令的路徑,相當於which命令。
type whatis
whatis is hashed (/usr/bin/whatis)
type which
which is hashed (/usr/bin/which)
type whereis
whereis is hashed (/usr/bin/whereis)
type man
man is hashed (/usr/bin/man)
type locate
locate is hashed (/usr/bin/locate)
type find
find is hashed (/usr/bin/find)
type type
type is a shell builtin
type cd
cd is a shell builtin
type grep
grep is aliased to `grep --color=auto'
type cat
cat is /bin/cat
type vim
vim is hashed (/usr/bin/vim)
type -p vim
/usr/bin/vim
type python
python is /usr/bin/python