查找/etc目錄下以conf結尾的文件shell
find /etc -name '*conf'
複製代碼
查找當前目錄文件名爲abc的文件,不區分大小寫spa
find ./ -iname abc
複製代碼
查找當前目錄文件全部者爲testuser的文件code
find ./ -user testuser
複製代碼
查找文件屬組爲work的全部文件xml
find . -group work
複製代碼
例1:查找/etc目錄下小於10000字節的文件class
find /etc -size -10000c
複製代碼
例2:查找/etc目錄下大於1M的文件test
find /etc -size +1M
複製代碼
例1:查找/etc目錄下5天以內修改且以conf結尾的文件file
find /etc -mtime -5 -name '*.conf'
複製代碼
例2:查找/etc目錄下10天以前修改且屬主爲root的文件搜索
find /etc -mtime +10 -user root
複製代碼
例1:查找/etc目錄下30分鐘以前修改的文件權限
find /etc -mmin +30
複製代碼
例2:查找/etc目錄下30分鐘以內修改的目錄command
find /etc -mmin -30 -type d
複製代碼
例0:在/etc下的3級子目錄開始搜索
find /etc -mindepth 3
複製代碼
例1:在/etc下搜索符合條件的文件,但最多搜索到2級子目錄
find /etc -maxdepth 3 -name '*.conf'
複製代碼
例2:
find ./etc/ -type f -name '*.conf' -size +10k -maxdepth 2
複製代碼
find . -type f -nouser
複製代碼
find . -type f -nogroup
複製代碼
find . -perm 664
複製代碼
例1:查找當前目錄下全部普通文件,但排除test目錄
find . -path ./etc -prune -o -type f
複製代碼
例2:查找當前目錄下全部普通文件,但排除etc和opt目錄
find . -path ./etc -prune -o -path ./opt -prune -o -type f
複製代碼
例3:查找當前目錄下全部普通文件,但排除etc和opt目錄,但屬主爲hdfs
find . -path ./etc -prune -o -path ./opt -prune -o -type f -a -user hdfs
複製代碼
例4:查找當前目錄下全部普通文件,但排除etc和opt目錄,但屬主爲hdfs,且文件大小必須大於500字節
find . -path ./etc -prune -o -path ./opt -prune -o -type f -a -user hdfs -a -size +500c
複製代碼
find /etc -newer a
複製代碼
例1:搜索/etc下的文件(非目錄),文件名以conf結尾,且大於10k,而後將其刪除
find ./etc/ -type f -name '*.conf' -size +10k -exec rm -f {} \;
複製代碼
例2:將/var/log/目錄下以log結尾的文件,且更改時間在7天以上的刪除
find /var/log/ -name '*.log' -mtime +7 -exec rm -rf {} \;
複製代碼
例3:搜索條件和例子1同樣,只是不刪除,而是將其複製到/root/conf目錄下
find ./etc/ -size +10k -type f -name '*.conf' -exec cp {} /root/conf/ \;
複製代碼
例1:查找當前目錄下,屬主不是hdfs的全部文件
find . -not -user hdfs | find . ! -user hdfs
複製代碼
例2:查找當前目錄下,屬主屬於hdfs,且大小大於300字節的文件
find . -type f -a -user hdfs -a -size +300c
複製代碼
例3:查找當前目錄下的屬主爲hdfs或者以xml結尾的普通文件
find . -type f -a \( -user hdfs -o -name '*.xml' \)
複製代碼