標籤:linux which whereis locate
1. 檔案名稱尋找
使用find查詢時,由於磁碟查詢,所以速度較慢,所以linux下查詢更常使用which, whereis, locate來查詢,由於是利用資料庫查詢,所以速度很快。
2. which
我們常用的ls命令,如果我們想知道這些常用命令放在哪兒, 就使用which命令來查詢地址。which使用PATH 環境變數去尋找檔案名稱,which -a 返回所有的查到的命令, 預設返回第一條。
$ which grep/bin/grep$ which llalias ll='ls -l --color=tty' /bin/ls #使用alias別名
3. whereis
whereis用來查詢程式名
$ whereiswhereis [ -sbmu ] [ -SBM dir ... -f ] name...-b : 尋找二進位格式檔案-s : 尋找source 源檔案-m : 尋找在說明檔案manual路徑下的檔案-u : 尋找不在上述三個選項中的特殊檔案
例如
$ whereis grepgrep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz#查詢二進位檔案$ whereis -b grep grep: /bin/grep#查詢手冊說明檔案 man grep $ whereis -m grepgrep: /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz
3. locate
linux將系統內檔案列在一個資料庫檔案(/var/lib/slocate/slocate.db)。locate通過資料庫檔案查詢。
一般這個檔案每天更新一次, 配置在/etc/updatedb.conf裡面配置是否每天更新,以及更新目錄。可以手動運行
$ updatedb
來更新資料庫。使用locate,後面跟命令即可
$ locate passwd
地址: http://blog.csdn.net/yonggang7/article/details/37960767
linux檔案名稱尋找which,whereis,locate