Linux的五個文件查找命令:find,locate,whereis,which,type
find:查找文件或目錄所在路徑
- 格式:find [路徑] [表達式]
- 表達式:
- -name :查找名為filename的文件
- -perm :按執行權限來查找
- -empty :查找空文件或空目錄
- -user :按文件屬主來查找
- -group :按組來查找
- -nogroup :查無有效屬組的文件,即文件的屬組在/etc/groups中不存在
- -nouser :查無有效屬主的文件,即文件的屬主在/etc/passwd中不存
- -mtime :按文件更改時間來查找文件
- -atime :按文件訪問時間來查找文件
- -ctime :按文件創建時間來查找文件
- -newer :查更改時間更新的文件或目錄
- -type :查是塊設備b、目錄d、字符設備c、管道p、符號鏈接l、普通文件f
- -size n[c] :查找大小為n塊(512字節)[或n字節]的文件
- -inum :根據i節點查找
- -depth :使查找在進入子目錄前先行查找完本目錄
- -fstype :查位於某一類型文件系統中的文件,這些文件系統類型通常可 在/etc/fstab中找到
- -mount :查文件時不跨越文件系統mount點
- -cpio :對匹配的文件使用cpio命令,將他們備份到磁帶設備中
- -prune :忽略某個目錄
- -maxdepth :查詢的目錄深度
-
- -exec :查找文件並執行後面的命令 find ... -exec CMD {} \;
- -ok :詢問是否要執行後面的命令 find ... -ok CMD {} \;
-perm mode表示嚴格匹配
-perm -mode 表示mode中轉換成二進制的1必須
全部匹配(不管0位)
-perm +mode 表示mode中轉換成二進制的1必須
部分匹配(不管0位)
-ctime/atime/mtime/cmin/amin/mmin:按時間查找
以天為單位的:ctime、atime、mtime
以分鐘為單位的:cmin、amin、mmin
c--change表示文件的屬性被修改過
a--access
m--modify表示文件的內容被修改過
+n表示n天以前
-n表示n天以內
- [root@rhel6 ~]# find /etc/ -name "host*" "查詢/etc/目錄(包括子目錄)中以host開頭的文件或目錄"
- [root@rhel6 ~]# find -type l "查詢當前目錄下文件類型為鏈接的文件"
- [root@rhel6 ~]# find -size +10000000c "查詢當前目錄中>10M的文件"
- [root@rhel6 ~]# find -size -1K "查詢當前目錄中<1K的文件"
- [root@rhel6 ~]# find /etc -name inittab -o -size +17M "查詢/etc/目錄中文件名為inittab或文件>17M的文件"
- [root@rhel6 ~]# find /etc -name "*.conf" [-a] -size +20k "查詢/etc/目錄中文件名為*.conf且文件<20k的文件"
- [root@rhel6 ~]# find /etc/* -name "*.conf" -not -name "*http*" "查詢/etc目錄中文件名為*.conf但不包含http的文件"
- [root@rhel6 ~]# find /etc/ -empty "查詢/etc/目錄中的空文件或空目錄"
- [root@rhel6 ~]# find /var -user Oracle "查詢/var/目錄中屬於用戶oracle的文件或目錄"
- [root@rhel6 ~]# find /home -group xfcy
- [root@rhel6 ~]# find -inum 1024 "查詢當前目錄中 i 節點為1024的文件或目錄"
- [root@rhel6 ~]# find -newer new "查詢當前目錄中比文件new還新的文件或目錄"
- [root@rhel6 ~]# find /etc/ -nouser -o -nogroup "查詢/etc/目錄中不屬於本地用戶的文件或目錄(危險文件)"
- [root@rhel6 ~]# find /data/ -mmin -10 "查詢/data/目錄中十分鐘內文件內容被修改過的文件"
- [root@rhel6 ~]# find /proc/ -type f -maxdepth 1 "查詢/data/目錄中文件類型為普通文件的文件且不查詢子目錄"
-
- [root@rhel6 ~]# find /data/ -mtime -10 -exec rm {} \; "查詢/data/目錄中十分鐘內內容被修改過的文件並將其刪除"
- [root@rhel6 ~]# find /data/ -mtime -10 -ok rm {} \; "查詢/data/目錄中十分鐘內內容被修改過的文件並詢問是否將其刪除(y/n)"