格式:
find path option file
path:查找的目錄路徑
option:按什么進行查找
file: 查找的文件特征
(如果查不到,就將文件名加""試試)
find -name april* 在當前目錄下查找以april開始的文件
find -name april* > a.txt 在當前目錄下查找以april開始的文件,並把結果輸出到a.txt中
find -name ap* -o -name may* 查找以ap或may開頭的文件
find /tmp -name wa* -type l 在/tmp下查找名為wa開頭且類型為符號鏈接的文件
find /home -mtime -2 在/home下查最近兩天內改動過的文件
find /home -atime -1 查/home下1天之內被存取過的文件
find /home -mmin +60 在/home下查60分鍾前改動過的文件
find /home -amin +30 在/home下查最近30分鍾前被存取過的文件
find /home -newer tmp.txt 在/home下查更新時間比tmp.txt近的文件或目錄
find /home -anewer tmp.txt 在/home下查存取時間比tmp.txt近的文件或目錄
find /home -used -2 列出/home中文件或目錄被改動過之后,在2日內被存取過的文件或目錄
find /home -user cnscn 列出/home目錄內屬於用戶cnscn的文件或目錄
find /home -uid +501 列出/home目錄內用戶的識別碼大於501的文件或目錄
find /home -group cnscn 列出/home內組為cnscn的文件或目錄
find /home -gid 501 列出/home內組id為501的文件或目錄
find /home -nouser 列出/home內不屬於本地用戶的文件或目錄
find /home -nogroup 列出/home內不屬於本地組的文件或目錄
find /home -maxdepth 4 -name tmp.txt 列出/home內的tmp.txt 查時深度最多為3層
find /home -mindepth 3 -maxdepth 5 -name tmp.txt 在/home的第二層到第四層之間查tmp.txt
find /home -empty 查找/home中大小為0的文件或空目錄
find /home -size +512k 查/home中大於512k的文件
find /home -size -512k 查/home中小於512k的文件
find /home -links +2 查/home中硬連接數大於2的文件或目錄
find /home -perm 0700 查/home中權限為700的文件或目錄
find -type f -exec ls -l {} \; 查當前目錄下的所有普通文件,並在-exec選項中使用ls -l命令將它們列出
find -name a.txt -ok rm {} \; 查當前目錄下的a.txt並詢問是否刪除
把當前目錄下的file移動到/test下:
find -type f -exec mv {} /test \;
刪除指定時間之前的文件:
find -type f -name *.log -mtime +180 -exec rm {} \;