1. 文件名查找
使用find查詢時(shí),由于磁盤查詢,所以速度較慢,所以linux下查詢更常使用which, whereis, locate來查詢,由于是利用數(shù)據(jù)庫(kù)查詢,所以速度很快。
2. which
我們常用的ls命令,如果我們想知道這些常用命令放在哪兒, 就使用which命令來查詢地址。 which使用PATH 環(huán)境變量去查找文件名, which -a 返回所有的查到的命令, 默認(rèn)返回第一條。$ 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 : 查找二進(jìn)制格式文件
-s : 查找source 源文件
-m : 查找在說明文件manual路徑下的文件
-u : 查找不在上述三個(gè)選項(xiàng)中的特殊文件
例如$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz
#查詢二進(jìn)制文件
$ whereis -b grep
grep: /bin/grep
#查詢手冊(cè)說明文件 man grep
$ whereis -m grep
grep: /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz
4. locate
linux將系統(tǒng)內(nèi)文件列在一個(gè)數(shù)據(jù)庫(kù)文件(/var/lib/slocate/slocate.db)。 locate通過數(shù)據(jù)庫(kù)文件查詢。
一般這個(gè)文件每天更新一次, 配置在/etc/updatedb.conf 里面配置是否每天更新,以及更新目錄??梢允謩?dòng)運(yùn)行$ updatedb
來更新數(shù)據(jù)庫(kù)。使用locate,后面跟命令即可$ locate passwd