查詢linux下的檔案處在何方

2021-06-19 02:49:59 字數 4427 閱讀 5489

locate命令基於資料庫查詢,第一次執行時需首先執行updatedb命令更新資料庫。

語法:locate 

例如查詢stdio.h檔案在如:

[python]view plain

copy

[root@localhost sys]

# locate stdio.h

/usr/include/stdio.h  

/usr/include/bits/stdio.h  

/usr/include/boost/iostreams/filter/stdio.hpp  

/usr/include/c++/4.4.4

/tr1/stdio.h  

/usr/include/glib-2.0

/glib/gstdio.h  

/usr/include/libgsf-1

/gsf/gsf-infile-stdio.h  

/usr/include/libgsf-1

/gsf/gsf-input-stdio.h  

/usr/include/libgsf-1

/gsf/gsf-outfile-stdio.h  

/usr/include/libgsf-1

/gsf/gsf-output-stdio.h  

/usr/lib/i686-redhat-linux5e/include/stdio.h  

/usr/lib/i686-redhat-linux5e/include/bits/stdio.h  

/usr/lib/perl5/core/nostdio.h  

/usr/share/man/man0p/stdio.h.0p

.gz  

語法:find 《起始目錄》 《搜尋條件》 《動作》 

預設起始目錄是.(當前目錄)。

預設動作是輸出檔名。

[python]view plain

copy

[root@localhost sys]

# find /usr/ -name stdio.h

/usr/lib/i686-redhat-linux5e/include/stdio.h  

/usr/lib/i686-redhat-linux5e/include/bits/stdio.h  

/usr/include/c++/4.4.4

/tr1/stdio.h  

/usr/include/stdio.h  

/usr/include/bits/stdio.h  

搜尋出來的結果有區別,原因何在???

?語法:whereis

功能:除給出檔案全路徑外,同時給出可執行檔案對應的原始碼及man page檔案。

[python]view plain

copy

[root@localhost sys]

# whereis stdio.h

stdio: /usr/include/stdio.h /usr/share/man/man3/stdio.3.gz

語法:which

功能:在path環境變數列出的路徑中搜尋指定的檔案,給出檔案全路徑。

5.whatis

whatis command displays a single line description about a command.

[python]view plain

copy

[root@localhost ~]

# whatis ifconfig

ifconfig             (8

)  - configure a network inte***ce  

which檢視可執行檔案的位置

whereis檢視檔案的位置

locate配合資料庫檢視檔案位置

find實際搜尋硬碟查詢檔案名稱

1、which

語法:[root@redhat ~]# which 可執行檔名稱

例如:[root@redhat ~]# which passwd

/usr/bin/passwd

which是通過path環境變數到該路徑內查詢可執行檔案,所以基本的功能是尋找可執行檔案

2、whereis

語法:[root@redhat ~]# whereis [-bmsu] 檔案或者目錄名稱

引數說明:

-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檔案相關的檔案都查詢出來

[root@redhat ~]# whereis -b passwd

passwd: /usr/bin/passwd /etc/passwd

只將二進位制檔案查詢出來

和find相比,whereis查詢的速度非常快,這是因為linux系統會將系統內的所有檔案都記錄在乙個資料庫檔案中,當使用whereis和下面即將介紹的locate時,會從資料庫中查詢資料,而不是像find命令那樣,通過遍歷硬碟來查詢,效率自然會很高。

但是該資料庫檔案並不是實時更新,預設情況下時一星期更新一次,因此,我們在用whereis和locate查詢檔案時,有時會找到已經被刪除的資料,或者剛剛建立檔案,卻無法查詢到,原因就是因為資料庫檔案沒有被更新。

引數說明:

時間查詢引數:

-atime n :將n*24小時記憶體取過的的檔案列出來

-ctime n :將n*24小時內改變、新增的檔案或者目錄列出來

-mtime n :將n*24小時內修改過的檔案或者目錄列出來

-newer file :把比file還要新的檔案列出來

名稱查詢引數:

-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

當我們用whereis和locate無法查詢到我們需要的檔案時,可以使用find,但是find是在硬碟上遍歷查詢,因此非常消耗硬碟的資源,而且效率也非常低,因此建議大家優先使用whereis和locate。

locate 是在資料庫裡查詢,資料庫大至每天更新一次。

whereis 可以找到可執行明令和man page

find 就是根據條件查詢檔案。

which 可以找到可執行檔案和別名(alias)

linux下查詢某個檔案

參考 一.通過檔名查詢法 舉例說明,假設你忘記了httpd.conf這個檔案在系統的哪個目錄 下,甚至在系統的某個地方也不知道,則這是可以使用如下命令 這個命令語法看起來很容易就明白了,就是直接在find後面寫上 name,表明要求系統按照檔名查詢,最後寫上httpd.conf這個目標檔名即可。稍等...

Linux下查詢檔案

linux下查詢檔案真是太不方便了,因為我不會這些命令,學了幾個,用著還行 find是乙個非常有效的工具,它可以遍歷當前目錄甚至於整個檔案系統來查詢某些檔案或目錄.主要選項 name 按照檔名查詢檔案 perm 按照檔案許可權來查詢檔案 prune 不在當前指定的目錄中查詢 user 按照檔案屬主來...

linux下查詢某個檔案

參考 一.通過檔名查詢法 舉例說明,假設你忘記了httpd.conf這個檔案在系統的哪個目錄 下,甚至在系統的某個地方也不知道,則這是可以使用如下命令 這個命令語法看起來很容易就明白了,就是直接在find後面寫上 name,表明要求系統按照檔名查詢,最後寫上httpd.conf這個目標檔名即可。稍等...