1. 檔案名查找
使用find查詢時,由于磁盤查詢,是以速度較慢, 是以linux下查詢更常使用which, whereis, locate來查詢,由于是利用資料庫查詢,是以速度很快。
2. which
我們常用的ls指令,如果我們想知道這些常用指令放在哪兒, 就使用which指令來查詢位址。 which使用PATH 環境變量去查找檔案名, which -a 傳回所有的查到的指令, 預設傳回第一條。
$ which grep
/bin/grep
$ which ll
alias ll='ls -l --color=tty'
/bin/ls
#使用alias别名
3. whereis
whereis用來查詢程式名
$ whereis
whereis [ -sbmu ] [ -SBM dir ... -f ] name...
-b : 查找二進制格式檔案
-s : 查找source 源檔案
-m : 查找在說明檔案manual路徑下的檔案
-u : 查找不在上述三個選項中的特殊檔案
例如
$ whereis grep
grep: /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 grep
grep: /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