+n 表示大于n
-n 表示小于n
n 表示等于n
还有其他时间(如atime,ctime)的比较,用法相同。
选项-newer file表示搜索到的文件比指定的file要‘新'(上次内容被修改离现在时间更短):
[root@centos7 temp]# find . -name "file1?" -newer file12 ./file10 ./file11 [root@centos7 temp]#
选项-path pattern文件名匹配pattern(通配符):
[root@centos7 temp]# find . -name "file1?" -path "./file1[13]" ./file11 ./file13 [root@centos7 temp]#
注意pattern匹配时不会对/和.进行特殊处理。
通常-path会配合选项-prune使用,表示对某目录的排除:
[root@centos7 temp]# find . -name "file*" ./file10 ./file12 ./file11 ./tmp/file ./file13 [root@centos7 temp]# [root@centos7 temp]# find . -path "./tmp" -prune -o -name "file*" -print ./file10 ./file12 ./file11 ./file13 [root@centos7 temp]#
这里的-o表示或者,它和之前所说的-and都是操作符。表示表达式之间的逻辑关系。本例中可以理解为:如果目录匹配./tmp则执行-prune跳过该目录,否则匹配-name指定的文件并执行-print。
除这两个操作符外,操作符!或-not表示逻辑非,操作符(...)和数学运算中的括号类似,表示提高优先级:
[root@centos7 temp]# find . ! -path "./tmp*" -name "file*" ./file10 ./file12 ./file11 ./file13 [root@centos7 temp]# #排除多个目录: [root@centos7 temp]# find . ( -path "./tmp" -o -path "./abcd" ) -prune -o -name "file*" -print ./file10 ./file12 ./file11 ./file13 [root@centos7 temp]#
注意这里的(...)操作符需要被转义(为避免被shell解释为其他含义),在符号前加上反斜线''。(关于shell中的转义或引用我们会在讲bash编程时详述)
选项-type x表示搜索类型为x的文件,其中x的可能值包括b、c、d、p、f、l、s。它们和命令ls显示的文件类型一致(见基础命令介绍一),f代表普通文件。
[root@centos7 temp]# ln -s file13 file14 [root@centos7 temp]# ls -l file14 lrwxrwxrwx 1 root root 6 11月 1 12:29 file14 -> file13 [root@centos7 temp]# find . -type l ./file14 [root@centos7 temp]#
选项-perm mode表示搜索特定权限的文件:
[root@centos7 temp]# chmod 777 file14 [root@centos7 temp]# ls -l file1[3-4] -rwxrwxrwx 1 root root 137 10月 12 16:42 file13 lrwxrwxrwx 1 root root 6 11月 1 12:29 file14 -> file13 [root@centos7 temp]# [root@centos7 temp]# find . -perm 777 ./file13 ./file14 [root@centos7 temp]#
或表示成:
[root@centos7 temp]# find . -perm -g=rwx #表示文件所属组的权限是可读、可写、可执行。 ./file13 ./file14 [root@centos7 temp]#
选项-size n表示搜索文件大小
[root@centos7 temp]# find . -path "./*" -size +100c ./file10 ./file13 [root@centos7 temp]#










