欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux下which、whereis、locate、find 區(qū)別

  發(fā)布時(shí)間:2016-11-21 20:18:55   作者:佚名   我要評(píng)論
這篇文章主要介紹了Linux下which、whereis、locate、find 區(qū)別,需要的朋友可以參考下

我們經(jīng)常在Linux要查找某個(gè)文件或命令,但不知道放在哪里了,可以使用下面的一些命令來(lái)搜索。

which      查看可執(zhí)行文件的位置
whereis    查看文件的位置
locate     配合數(shù)據(jù)庫(kù)查看文件位置
find       實(shí)際搜尋硬盤(pán)查詢(xún)文件名稱(chēng)

1、which

語(yǔ)法: which 可執(zhí)行文件名稱(chēng)
例如:
[root@redhat ~]# which passwd
/usr/bin/passwd
which是通過(guò) PATH 環(huán)境變量到該路徑內(nèi)查找可執(zhí)行文件,所以基本的功能是尋找可執(zhí)行文件

2、whereis

語(yǔ)法: whereis [-bmsu] 文件或者目錄名稱(chēng)
參數(shù)說(shuō)明:
-b : 只找二進(jìn)制文件
-m: 只找在說(shuō)明文件manual路徑下的文件
-s : 只找source源文件
-u : 沒(méi)有說(shuō)明文檔的文件
例如:
[root@redhat ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/bin/X11/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/man1/passwd.1ssl.gz
將和passwd文件相關(guān)的文件都查找出來(lái)

[root@redhat ~]# whereis -b passwd
passwd: /usr/bin/passwd /etc/passwd /usr/bin/X11/passwd
只將二進(jìn)制文件 查找出來(lái)

和find相比,whereis查找的速度非常快,這是因?yàn)閘inux系統(tǒng)會(huì)將系統(tǒng)內(nèi)的所有文件都記錄在一個(gè)數(shù)據(jù)庫(kù)文件中,當(dāng)使用whereis和下面即將介紹的locate時(shí),會(huì)從數(shù)據(jù)庫(kù)中查找數(shù)據(jù),而不是像find命令那樣,通過(guò)遍歷硬盤(pán)來(lái)查找,效率自然會(huì)很高。
但是該數(shù)據(jù)庫(kù)文件并不是實(shí)時(shí)更新,默認(rèn)情況下時(shí)一星期更新一次,因此,我們?cè)谟脀hereis和locate 查找文件時(shí),有時(shí)會(huì)找到已經(jīng)被刪除的數(shù)據(jù),或者剛剛建立文件,卻無(wú)法查找到,原因就是因?yàn)閿?shù)據(jù)庫(kù)文件沒(méi)有被更新。

3、 locate

語(yǔ)法: locate 文件或者目錄名稱(chēng)
例 如:

[root@redhat ~]# locate passwd 
/etc/passwd
/etc/passwd-
/etc/cron.daily/passwd
/etc/init/passwd.conf
/etc/init.d/passwd
/etc/pam.d/chpasswd
/etc/pam.d/passwd
/etc/security/opasswd
………… 


4、 find

語(yǔ)法: find 路徑 參數(shù)
參數(shù)說(shuō)明:
時(shí)間查找參數(shù):
-atime n :將n*24小時(shí)內(nèi)存取過(guò)的的文件列出來(lái)
-ctime n :將n*24小時(shí)內(nèi)改變、新增的文件或者目錄列出來(lái)
-mtime n :將n*24小時(shí)內(nèi)修改過(guò)的文件或者目錄列出來(lái)
-newer file :把比f(wàn)ile還要新的文件列出來(lái)
名稱(chēng)查找參數(shù):
-gid n       :尋找群組ID為n的文件
-group name  :尋找群組名稱(chēng)為name的文件
-uid n       :尋找擁有者ID為n的文件
-user name   :尋找用戶(hù)者名稱(chēng)為name的文件
-name file   :尋找文件名為file的文件(可以使用通配符)
例如:

[root@redhat ~]# find / -name zgz 
/home/zgz 
/home/zgz/zgz 
/home/weblogic/bea/user_projects/domains/zgz 
/home/Oracle/product/10g/cfgtoollogs/dbca/zgz 
/home/oracle/product/10g/cfgtoollogs/emca/zgz 
/home/oracle/oradata/zgz 
[root@redhat ~]# find / -name '*zgz*' 
/home/zgz 
/home/zgz/zgz1 
/home/zgz/zgzdirzgz 
/home/zgz/zgz 
/home/zgz/zgzdir 
/home/weblogic/bea/user_projects/domains/zgz 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00006 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00002 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00004 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00008 
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00005 

當(dāng)我們用whereis和locate無(wú)法查找到我們需要的文件時(shí),可以使用find,但是find是在硬盤(pán)上遍歷查找,因此非常消耗硬盤(pán)的資源,而且效率也非常低,因此建議大家優(yōu)先使用whereis和locate。

總結(jié):

which     只能查可執(zhí)行文件和別名(alias) ,并在PATH變量里面尋找
whereis   只能查二進(jìn)制文件(含可執(zhí)行文件)、說(shuō)明文檔,源文件等,從linux文件數(shù)據(jù)庫(kù)(/var/lib/slocate/slocate.db 或 /var/lib/mlocate/mlocate.db)尋找,所以有可能找到剛剛刪除,或者沒(méi)有發(fā)現(xiàn)新建的文件
locate    在數(shù)據(jù)庫(kù)里查找,數(shù)據(jù)庫(kù)大至每天更新一次,文件名是部分匹配(見(jiàn) 3 locate passwd 的結(jié)果:opasswd)
find      最強(qiáng)大,什么都能查,根據(jù)條件查找文件,在硬盤(pán)上查找,效率很低

相關(guān)文章

最新評(píng)論