find命令常用參數


-name

按照名稱進行查找,支持shell通配符。例如:查找指定目錄下名為test的文件或木目錄

[root@self ~]# find / -name 'test'

-type

按照文件或目錄的類型進行查找。

[root@self ~]# find / -type b		# 塊設備文件
[root@self ~]# find / -type f		# 文件
[root@self ~]# find / -type d		# 目錄
[root@self ~]# find / -type c		# 字符設備文件
[root@self ~]# find / -type p		# 管道文件
[root@self ~]# find / -type l		# 符號鏈接文件
[root@self ~]# find / -type s		# socket文件

-size

按照文件大小進行查找,+表示大於,-表示小於

[root@self ~]# find / -size +1c		# 字節數
[root@self ~]# find / -size -1w		# 字(2字節)
[root@self ~]# find / -size +1b		# 代表 512 位元組的區塊(默認為b)
[root@self ~]# find / -size -1k		# 表示 kilo bytes(1024字節)
[root@self ~]# find / -size +1M		# 表示兆字節(1048576字節)
[root@self ~]# find / -size -1G		# 表示千兆字節(1073741824字節)

-empty

查找空文件或目錄

[root@self ~]# find / -empty

-inum

按照Inode進行查找

[root@self ~]# find / -inum 17798702

按照鏈接數查找

[root@self ~]# find / -links 3

-perm

按照文件的權限進行查找,

  • mode - 嚴格匹配,必須等於指定的權限
  • -mode - 滿足指定的權限即可匹配(不在乎其他權限)
  • /mode - 滿足其中一個即可
[root@self ~]# find / -perm 0644	# 查找權限等於0644的目錄或文件
[root@self ~]# find / -perm 0644	# 查找權限大於等於0644的目錄或文件
[root@self ~]# find / -perm 0644	# 查找權限包含0644的目錄或文件
# 匹配只有屬主為r的文件或目錄(精確匹配)
[root@self ~]# find / -perm u+r
# 匹配

-user

按照文件的屬主進行查找

[root@self ~]# find / -user "root"	# 查找屬主為root的文件或目錄
[root@self ~]# find / -nouser		# 查找屬主不存在的文件或目錄

-group

按照文件的屬組進行查找

[root@self ~]# find / -group "root"	# 查找屬組為root的文件或目錄
[root@self ~]# find / -nogroup		# 查找屬組不存在的文件或目錄

-atime

按照最后訪問時間進行查找(天數)

# 查找30天前訪問的文件或目錄
[root@self ~]# find / -atime +30
# 查找30天內訪問的文件或目錄
[root@self ~]# find / -atime -30

-ctime

按照最后更改事件進行查找(天數)

# 查找30天前更改的文件或目錄
[root@self ~]# find / -ctime +30
# 查找30天內更改的文件或目錄
[root@self ~]# find / -ctime -30

-mtime

按照最后修改事件進行查找(天數)

# 查找30天前修改的文件或目錄
[root@self ~]# find / -mtime +30
# 查找30天內修改的文件或目錄
[root@self ~]# find / -mtime -30

-amin

按照最后訪問時間進行查找(分鍾)

# 查找30分鍾前訪問的文件或目錄
[root@self ~]# find / -amin +1
# 查找30分鍾內訪問的文件或目錄
[root@self ~]# find / -amin -1

-cmin

按照最后更改事件進行查找(分鍾)

# 查找30分鍾前更改的文件或目錄
[root@self ~]# find / -cmin +1
# 查找30分鍾內更改的文件或目錄
[root@self ~]# find / -cmin -1

-mmin

按照最后修改時間進行查找(分鍾)

# 查找30分鍾前修改的文件或目錄
[root@self ~]# find / -mmin +1
# 查找30分鍾內修改的文件或目錄
[root@self ~]# find / -mmin -1

-depth

從指定目錄下最深層的子目錄開始查找

[root@self ~]# find /etc/ -depth

-maxdepth

設置查找目錄的最大層級

# 只在一層內查找
[root@self ~]# find /etc/ -maxdepth 2

-mindepth

設置查找目錄的最小層級

# 最少查找
[root@self ~]# find /etc/ -mindepth 2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM