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
原文地址:https://www.cnblogs.com/liuhedong/p/10813372.html