少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
          我們經(jīng)常在linux要查找某個文件,但不知道放在哪里了,可以使用下面的一些命令來搜索。這些是從網(wǎng)上找到的資料,因為有時很長時間不會用到,當(dāng)要用的時候經(jīng)常弄混了,所以放到這里方便使用。 
          which       查看可執(zhí)行文件的位置 
          whereis    查看文件的位置 
          locate       配 合數(shù)據(jù)庫查看文件位置 
          find          實際搜尋硬盤查詢文件名稱 

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

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

          [root@redhat ~]# whereis -b passwd 
          passwd: /usr/bin/passwd /etc/passwd 
          只將二進制文件 查找出來 

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

          3、 locate 
          語法: 
          [root@redhat ~]# locate 文件或者目錄名稱 
          例 如: 
          [root@redhat ~]# locate passwd 
          /home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_DB_war/DB.war/jsp/as/user/passwd.jsp
          /home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_admin_war/admin.war/jsp/platform/passwd.jsp
          /lib/security/pam_unix_passwd.so 
          /lib/security/pam_passwdqc.so 
          /usr/include/rpcsvc/yppasswd.x 
          /usr/include/rpcsvc/yppasswd.h 
          /usr/lib/perl5/5.8.5/i386-linux-thread-multi/rpcsvc/yppasswd.ph 
          /usr/lib/kde3/kded_kpasswdserver.la 
          /usr/lib/kde3/kded_kpasswdserver.so 
          /usr/lib/ruby/1.8/webrick/httpauth/htpasswd.rb 
          /usr/bin/vncpasswd 
          /usr/bin/userpasswd 
          /usr/bin/yppasswd 
          ………… 

          4、 find 
          語法: 
          [root@redhat ~]# find 路徑 參數(shù) 
          參 數(shù)說明: 
          時間查找參數(shù): 
          -atime n :將n*24小時內(nèi)存取過的的文件列出來 
          -ctime n :將n*24小時內(nèi)改變、新增的文件或者目錄列出來 
          -mtime n :將n*24小時內(nèi)修改過的文件或者目錄列出來 
          -newer file :把比file還要新的文件列出來 
          名稱查找參數(shù): 
          -gid n       :尋找群組ID為n的文件 
          -group name  :尋找群組名稱為name的文件 
          -uid n       :尋找擁有者ID為n的文件 
          -user name   :尋找用戶者名稱為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無法查找到我們需要的文件時,可以使用find,但是find是在硬盤上遍歷查 找,因此非常消耗硬盤的資源,而且效率也非常低,因此建議大家優(yōu)先使用whereis和locate。 
          locate 是在數(shù)據(jù)庫里查找,數(shù)據(jù)庫大至每天更新一次。 
          whereis 可以找到可執(zhí)行命令和man page 
          find 就是根據(jù)條件查找文件。 
          which 可以找到可執(zhí)行文件和別名(alias)
          posted on 2012-11-09 16:19 abin 閱讀(378) 評論(0)  編輯  收藏 所屬分類: linux
          主站蜘蛛池模板: 嘉祥县| 沅江市| 福清市| 河津市| 定襄县| 博乐市| 德清县| 青龙| 浦东新区| 潢川县| 梅州市| 汉源县| 焉耆| 调兵山市| 铅山县| 东乌珠穆沁旗| 通辽市| 建平县| 遵化市| 米林县| 余干县| 镇原县| 荔浦县| 诸暨市| 塔河县| 长武县| 永嘉县| 马龙县| 广灵县| 马山县| 迁安市| 宁国市| 浏阳市| 阿巴嘎旗| 文昌市| 革吉县| 平利县| 波密县| 遵义市| 云安县| 五莲县|