歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下的文件查找命令

Linux下的文件查找命令

日期:2017/2/28 14:50:54   编辑:Linux教程
Linux的五個文件查找命令:find,locate,whereis,which,type

find:查找文件或目錄所在路徑

  1. 格式:find [路徑] [表達式]
  2. 表達式:
  3. -name :查找名為filename的文件
  4. -perm :按執行權限來查找
  5. -empty :查找空文件或空目錄
  6. -user :按文件屬主來查找
  7. -group :按組來查找
  8. -nogroup :查無有效屬組的文件,即文件的屬組在/etc/groups中不存在
  9. -nouser :查無有效屬主的文件,即文件的屬主在/etc/passwd中不存
  10. -mtime :按文件更改時間來查找文件
  11. -atime :按文件訪問時間來查找文件
  12. -ctime :按文件創建時間來查找文件
  13. -newer :查更改時間更新的文件或目錄
  14. -type :查是塊設備b、目錄d、字符設備c、管道p、符號鏈接l、普通文件f
  15. -size n[c] :查找大小為n塊(512字節)[或n字節]的文件
  16. -inum :根據i節點查找
  17. -depth :使查找在進入子目錄前先行查找完本目錄
  18. -fstype :查位於某一類型文件系統中的文件,這些文件系統類型通常可 在/etc/fstab中找到
  19. -mount :查文件時不跨越文件系統mount點
  20. -cpio :對匹配的文件使用cpio命令,將他們備份到磁帶設備中
  21. -prune :忽略某個目錄
  22. -maxdepth :查詢的目錄深度
  23. -exec :查找文件並執行後面的命令 find ... -exec CMD {} \;
  24. -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天以內
  1. [root@rhel6 ~]# find /etc/ -name "host*" "查詢/etc/目錄(包括子目錄)中以host開頭的文件或目錄"
  2. [root@rhel6 ~]# find -type l "查詢當前目錄下文件類型為鏈接的文件"
  3. [root@rhel6 ~]# find -size +10000000c "查詢當前目錄中>10M的文件"
  4. [root@rhel6 ~]# find -size -1K "查詢當前目錄中<1K的文件"
  5. [root@rhel6 ~]# find /etc -name inittab -o -size +17M "查詢/etc/目錄中文件名為inittab或文件>17M的文件"
  6. [root@rhel6 ~]# find /etc -name "*.conf" [-a] -size +20k "查詢/etc/目錄中文件名為*.conf且文件<20k的文件"
  7. [root@rhel6 ~]# find /etc/* -name "*.conf" -not -name "*http*" "查詢/etc目錄中文件名為*.conf但不包含http的文件"
  8. [root@rhel6 ~]# find /etc/ -empty "查詢/etc/目錄中的空文件或空目錄"
  9. [root@rhel6 ~]# find /var -user Oracle "查詢/var/目錄中屬於用戶oracle的文件或目錄"
  10. [root@rhel6 ~]# find /home -group xfcy
  11. [root@rhel6 ~]# find -inum 1024 "查詢當前目錄中 i 節點為1024的文件或目錄"
  12. [root@rhel6 ~]# find -newer new "查詢當前目錄中比文件new還新的文件或目錄"
  13. [root@rhel6 ~]# find /etc/ -nouser -o -nogroup "查詢/etc/目錄中不屬於本地用戶的文件或目錄(危險文件)"
  14. [root@rhel6 ~]# find /data/ -mmin -10 "查詢/data/目錄中十分鐘內文件內容被修改過的文件"
  15. [root@rhel6 ~]# find /proc/ -type f -maxdepth 1 "查詢/data/目錄中文件類型為普通文件的文件且不查詢子目錄"
  16. [root@rhel6 ~]# find /data/ -mtime -10 -exec rm {} \; "查詢/data/目錄中十分鐘內內容被修改過的文件並將其刪除"
  17. [root@rhel6 ~]# find /data/ -mtime -10 -ok rm {} \; "查詢/data/目錄中十分鐘內內容被修改過的文件並詢問是否將其刪除(y/n)"
Copyright © Linux教程網 All Rights Reserved