檔案搜尋命令

2022-06-20 02:15:08 字數 2215 閱讀 9639

1,檔案搜尋命令locate(速度快)

locate 檔名      #在後台資料庫(mlocate)中按檔名搜尋,搜尋速度更快

/var/lib/mlocate      #locate命令所搜尋的資料庫(預設一天更新一次)

updatedb      #更新資料庫

/etc/updatedb.conf配置檔案(locate搜尋命令遵守此配置檔案)

prune_bind_mounts="yes"      #開啟搜尋限制

prunefs=      #搜尋時,不搜尋的檔案系統

prunenames=      #搜尋時,不搜尋的檔案型別

prunepaths=      #搜尋時,不搜尋的路徑

locate包的安裝:

在yum中,locate的安裝包名為mlocate(yum list | grep locate可以檢視),安裝方法:yum -y install mlocate

2.命令搜尋命令whereis與which

whereis 命令名      #搜尋命令所在路徑及幫助文件所在位置

選項:-b  只查詢可執行檔案

-m 只查詢幫助檔案

whatis 檔名        #檢視命令功能

which 檔名      #搜尋命令所在路徑及別名

path環境變數

path環境變數:定義的是系統搜尋命令的路徑

echo $path

3,檔案搜尋命令find

find [搜尋範圍] [搜尋條件]      #搜尋檔案

find / -name install.log

#避免大範圍搜尋,會非常耗費系統資源

#find是在系統當中搜尋符合條件的檔名。如果需要匹配,使用萬用字元匹配,萬用字元是完全匹配

find -iname [檔名]            #不區分大小寫

find [搜尋路徑] -user [所有者]       #按照所有者搜尋

find [搜尋路徑] -nouser        #查詢沒有所有者的檔案

按照時間搜尋:

find /var/log/ -mtime +10        #查詢10天前修改的檔案

-10    10天內修改檔案

10    10天當天修改的檔案

+10    10天前修改的檔案

atime  檔案訪問時間

ctime  改變檔案屬性

mtime  修改檔案內容

按照檔案大小搜尋:

find /root -size 25k        #查詢檔案大小是25kb的檔案(可以用+-=)

find . -inum 26442        #查詢i節點是26442的檔案

find /etc -size +20k -a -size -50k      #查詢/etc/目錄下,大於20kb並且小於50kb的檔案

-a and邏輯與,兩個條件都滿足

-o or  邏輯或,兩個條件滿足乙個即可

對搜尋結果進行再處理:    

find /etc -size +20k -a -size -50k  -exec ls -lh {} \;

#查詢/etc/目錄下,大於20kb並且小於50kb的檔案,並顯示詳細資訊

#-exec 命令 {} \;  對搜尋結果執行操作

linux中的萬用字元

*    匹配任意內容

?    匹配任意乙個字元

匹配任意乙個中括號內的字元

4,字串搜尋命令grep

grep [選項] 字串 檔名        #在檔案當中匹配符合條件的字串

選項:-i    忽略大小寫

-v    排除指定字元

5,禁止find搜尋子目錄

find /mnt/lixian/ -maxdepth 1 -name "

file_name

"

注意:修改 -maxdepth 1 為  -maxdepth 2,為向下搜尋2層目錄,以此類推

檔案搜尋命令

檔案搜尋命令find 1.find 命令名稱 find 命令所在路徑 bin find 執行許可權 所有使用者 語法 find 搜尋範圍 匹配條件 功能描述 檔案搜尋 檔案搜尋命令 1.find etc name init 表示任意字元,單個字元 在目錄 etc中查詢檔案init iname不區分大...

linux檔案搜尋命令和命令搜尋命令

1.locate 速度快 find 搜尋全部檔案 1 locate 檔名 在後台資料庫中按檔名搜尋 2 資料庫所在位置 var lib mlocate 可以切換到該目錄下看看 3 用命令updatedb更新後台資料庫 4 配置檔案在 etc updatedb.config 開啟檔案搜尋位置限制時可以...

linux 檔案搜尋命令

1,locate 檔名 1 如果touch乙個檔案,locate不會搜尋出來,是因為這個不是實時查詢的,他是搜尋的檔案資源庫在 var lib molcate mlocate.db中,需要updatedb更新一下db這個檔案 2 locate不能查詢tmp目錄下的檔案 i 不區分大小寫 2,whic...