一、基本使用
1、查找文件名為test.txt的文件:
find / -name test.txt2、查找文件名中包含test的文件:
find / -name "*test*"3、查找更改時間在5天以內的文件:
find / -ctime -54、查找大小大於100M的文件:
find / -size +100M5、查找權限為755的文件:
find / -type f -perm 755二、使用-exec執行命令
1、查找文件名為test.txt的文件,並將其刪除:
find / -name test.txt -exec rm {} \;2、查找log文件,並將其壓縮為.gz格式:
find /var/log -name "*.log" -exec gzip {} \;3、查找大小超過10M的文件,並將其移動到指定目錄中:
find / -size +10M -exec mv {} /tmp/ \;三、使用-depth選項
1、查找當前目錄及其子目錄中,文件名為test.txt的文件,並按深度優先的順序進行顯示:
find . -depth -name test.txt2、查找當前目錄及其子目錄中,文件名為test.txt的文件,並刪除:
find . -depth -name test.txt -exec rm {} \;四、使用-prune選項
1、在查找過程中跳過指定目錄:
find / -path /var/log -prune -o -name "*.log" -print以上命令將跳過/var/log目錄,查找所有以.log結尾的文件。
五、使用-type選項
1、查找所有目錄:
find / -type d2、查找所有普通文件:
find / -type f3、查找所有符號鏈接文件:
find / -type l六、使用-mtime和-atime選項
1、查找文件最近一次修改時間在5天以內並且最近一次訪問時間在10天以內的文件:
find / -type f -mtime -5 -atime -102、查找文件最近一次修改時間在10天以內的文件,並按照修改時間進行排序:
find / -type f -mtime -10 | xargs ls -lt七、使用-user和-group選項
1、查找所有用戶為root的文件:
find / -type f -user root2、查找所有組為admin的文件:
find / -type f -group admin八、使用-size選項
1、查找文件大小大於100M的文件:
find / -type f -size +100M2、查找文件大小在10M到100M之間的文件:
find / -type f -size +10M -size -100M以上就是Linux運維工程師必備的find命令操作技巧。使用find命令可以更加方便快捷地查找和管理文件,在實際工作中十分實用。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/195507.html
微信掃一掃
支付寶掃一掃