linux find檔案查詢命令

2021-09-20 02:59:52 字數 1974 閱讀 6479

find命令 支援實時查詢,精確匹配,通過遍歷指定目錄中的所有檔案完成查詢,速度慢,但支援眾多查詢標準

講find命令之前,先介紹類似的檔案查詢命令 locate

search for files in a directory hierarchy

find [-h] [-l] [-p] [-d debugopts] [-olevel] [starting-point…] [expression]

使用:find 查詢路徑 查詢標準 查詢後的處理運作

tip1 find 常通過檔案萬用字元查詢檔案,用正規表示式較少

tip2 若乙個使用者刪除,但是此前使用者建立的檔案不會刪除,那麼其屬主是誰?

其檔案的屬主是其原使用者的id號

tip3 -type 檔案型別

tip4 -size 檔案大小

tip5 檔案時間戳查詢

tip6 -perm mode

/mode 內部有乙個滿足 -mode 同時滿足

find ./  -perm -001  查詢其他使用者有執行檔案的檔案

find ./ -perm -007 查詢其他使用者有讀寫執行許可權的檔案

find ./ -perm  -006 -exec chmod o-w {} \;  查詢其他使用者有寫許可權的檔案,並將其他使用者寫許可權去掉

find ./ -type d -ok chmod +x {} \; 查詢普通檔案,將其增加寫許可權

find ./ -perm -020 -exec mv {} {}.new \; 將組使用者有寫許可權和執行許可權的檔案,重新命名為***.new

find /home -name "*.sh" -a -perm -111 -exec chmod o-x {} \;

1.查詢/var 目錄下屬主為root並且屬組為mail的所有檔案

find /var -user root -group mail

2.查詢/tmp目錄下不屬於root,bin或者student的檔案

find /tmp -not -user root -a -user bin -a student

3.查詢/etc目錄下最近一周內內容修改過且不屬於root及student使用者的檔案

find /tmp -mtime -7 -a -not -user root

4.查詢當前系統上沒有屬主或屬組且最近一天內曾被訪問過的檔案,並將其屬組屬主均修改為root

find / -nouser -nogroup -atime -1 -exec chown root:root {} ;

5.查詢/etc目錄下大於1m的檔案,並將其檔名寫入/tmp/etc.largefile檔案中

find /etc -size 1m -exec echo {} >>/tmp/etc.largerfile ;

find /etc -size 1m >> /tmp/etc.largerfile

6.查詢/etc目錄下所有使用者都沒有寫許可權的檔案,顯示出其詳細資訊

find /etc -not -perm /222 -ls

find 常搭配 xargs 命令 從標磚輸入接收命令並執行的

find /etc -size +1m | xargs echo >> /tmp/etc.largerfile

find /etc -size +1m -exec echo {} >> /tmp/etc.largerfile

Linux find 查詢檔案

在日誌資料夾下判斷是否有web伺服器的日誌資料夾,寫了個指令碼 bin bash cd wls annuity acc for sys in cat wiiserver name list.txt do find logs sys name sys xargs echo en n 123.txt f...

linux find 查詢刪除檔案

find name log xargs rm rf 刪除在當前目錄下及子目錄中找到的所有log日誌 刪除find搜尋到的檔案 linux find 命令在指定目錄下查詢檔案。刪除目錄下所有萬用字元搜尋到的檔案 find name zui 副本.type f print exec rm rf 從當前目...

linux find 查詢檔案

1.根據名稱查詢某個目錄下的檔案 目錄 例子 查詢根目錄下的檔案名字為a.txt find name a.txt 2.根據名稱查詢某個目錄下型別為檔案的a.txt type f 檔案 d 目錄 find name a.txt type f 3.查詢某目錄下大小為在某個範圍的檔案 例子 查詢hive目...