基本語法:find [路徑] [參數] [action]
# find /tmp -perm 755 # 權限為 755 的檔案 # find /tmp -perm +222 # 任一類用戶有寫權限即可 # find /tmp -perm -222 # 所有類別用戶都需有寫權限 # find /tmp -size 2M # 大小等於 2M # find /tmp -size +2M # 大於 2M # find /tmp -size -2M # 小於 2M
-print # 預設動作
-ls # 以 ls 顯示結果
-ok [command] # 執行前詢問
-exec [command] # 直接執行不詢問
# find /tmp -atime +30 -exec rm -rf {} \; # {} 代表找到的檔案
# find /tmp -name "*.php" | xargs chmod a+x
# find /etc /tmp /root -name passwd # 多目錄以空格隔開 * 任意多個字元;? 單一字元;[] 括號內任一字元 # find /tmp -name "*.php" -a -user root # find /tmp -name "*.sql" -o user zhaoyn # find /tmp -not -user root
# find ./ -path "./server" -prune -o -name "*.log" -print # find ./ \( -path "./server" -o -path "./test" \) -prune -o -name "*.log" -print
掌握這些參數與範例,就能精準地在檔案系統中定位所需的檔案。