linux基礎命令 檔案搜尋命令

2021-10-23 04:55:49 字數 2231 閱讀 1930

列舉了檔案搜尋命令

一、檔案搜尋命令(find、locate、which、whereis、grep)

命令名稱:find

命令所在路徑:/bin/find

執行許可權:所有使用者

功能描述:檔案搜尋

語法:find [搜尋範圍] [匹配條件]

例項:1)在目錄/etc中查詢檔案config

# find  /etc -name config   

注:此搜尋為精準搜尋,-name 嚴格區分大小寫      -iname 不區分大小寫

使用萬用字元進行模糊搜尋 『*』:多個字元  ,『?』:單個字元

2)在根目錄下查詢大於100mb的檔案

# find / -size +204800  

注:+n大於  -n小於  n等於

3)在home目錄下查詢所有者為root的檔案

# find /home -user root

注:-group 根據所屬組查詢

4)在/etc下查詢5分鐘內被修改過屬性的檔案和目錄

# find /etc -cmin -5

注:-amin 訪問時間 access

-cmin 檔案屬性change(檔案屬性指檔案許可權、所有者....)

-mmin 檔案內容modify

5)在/etc下查詢大於50mb 小於100mb的檔案

# find /etc -size +102400 -a -size -204800

注:-a 兩個條件同時滿足

-o 兩個條件滿足乙個即可

6)在/etc下查詢config檔案並顯示其詳細資訊

# find /etc -name config -exec ls -l {} \;

注:-exec\-ok 命令{} \; 對搜尋結果進行操作。(-ok:詢問確認)

7)-type 根據檔案型別查詢 

8)-inum 根據i節點查詢

命令名稱:locate

命令所在路徑:/usr/bin/locate

執行許可權:所有使用者

功能描述:在檔案資料庫中查詢檔案(檔案資料庫定期更新,也可手動更新使用命令:updatedb,檔案資料庫不收錄/tmp目錄下檔案)

語法:locate 檔名 (區分大小寫,使用-i不區分)

範例:# locate config

命令名稱:which

命令所在路徑:/usr/bin/which

執行許可權:所有使用者

功能描述:搜尋命令所在目錄及別名資訊

語法:which [命令名稱]

範例:# which cd

[root@localhost tmp]# which cd

/bin/cd

[root@localhost tmp]# which ls

alias ls='ls --color=auto'

/bin/ls

[root@localhost tmp]# which useradd

/sbin/useradd

[root@localhost tmp]# which rm

alias rm='rm -i'

/bin/rm

[root@localhost tmp]#

命令名稱:whereis

命令所在路徑:/usr/bin/whereis

執行許可權:所有使用者

功能描述:搜尋命令所在目錄及幫助文件路徑

語法:whereis [命令名稱]

範例:# whereis ls

[root@localhost tmp]# whereis ls

ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

命令名稱:grep

命令所在路徑:/bin/grep

執行許可權:所有使用者

語法:grep -iv [指定字串] [檔案]

功能描述:在檔案中搜尋字串匹配的行並輸出

-i 不區分大小寫

-v 排除指定字串

範例:# grep  exception /home/log/my.log

日誌檢視常用命令:

# cat all.8082.log|grep 'exception'
在使用 -v 檢視配置檔案排除注釋#時候,在配置檔案中,注釋以#開頭,需要加『^#』 表示以#開頭

linux 基礎 檔案搜尋命令

locate which whereis grep 單詞 name size user group amin cmin mmin 命令名稱 命令含義 amin 訪問時間 access cmin 檔案屬性 change mmin 檔案內容 modify 命令名稱 命令含義 a兩個條件同時滿足 o兩個檔...

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...