目录
2. 指定所有者(用户、组、其他人)至少有一个拥有此权限即可
1. 查找当前目录下,所属用户为root的文件,并把匹配到的每一个文件通过 chown 修改所有者为 tom。
2. 查找家目录下面,以 .txt 结尾的文件,并把匹配到的每一个文件执行删除操作,-ok 与 -exec 不同之处在于会提示需要用户是否要执行此操作
3. 查找当前目录下,以 .txt 结尾的文件,并把匹配到的每一个文件通过 cat 命令显示屏幕上,然后执行 > /all.txt 把结果写入到 all.txt 文件中
5. 找出当前目录下所有.txt文件并以“File:文件名”的形式打印出来
7. 查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk
3. 忽略错误信息,使用 2 > /dev/null 重定向到垃圾桶
-user -group
通过所有者来查找
1. 指定所属的用户
find . -user syslog2. 指定所属的组
find . -group www -perm Searching files by permissions • Search for files which are executable but not readable. $ find /sbin /usr/sbin -executable \! -readable -print # 搜索 /sbin /usr/sbin 目录下 能执行但是不能读的权限文件 • Search for files which have read and write permission for their owner, and group, but which other users can read but not write to. $ find . -perm 664 # 搜索权限是644的文件 Files which meet these criteria but have other permissions bits set (for example if someone can execute the file) will not be matched. • Search for files which have read and write permission for their owner and group, and which other users can read, without regard to the presence of any extra permission bits (for example the executable bit). $ find . -perm -664 # 搜索权限是644的文件,不考虑是否存在任何额外的权限位 This will match a file which has mode 0777, for example. • Search for files which are writable by somebody (their owner, or their group, or anybody else). $ find . -perm /222 • Search for files which are writable by either their owner or their group. $ find . -perm /220 $ find . -perm /u+w,g+w $ find . -perm /u=w,g=w All three of these commands do the same thing, but the first one uses the octal representation of the file mode, and the other two use the symbolic form. The files don't have to be writable by both the owner and group to be matched; either will do. • Search for files which are writable by both their owner and their group. $ find . -perm -220 $ find . -perm -g+w,u+w Both these commands do the same thing. • A more elaborate search on permissions. $ find . -perm -444 -perm /222 \! -perm /111 $ find . -perm -a+r -perm /a+w \! -perm /a+x These two commands both search for files that are readable for everybody (-perm -444 or -perm -a+r), have at least one write bit set (-perm /222 or -perm /a+w) but are not executable for anybody (! -perm /111 or ! -perm /a+x respectively).通过权限来查找
1. 指定精确的权限查找
find / -perm 6442. 指定所有者(用户、组、其他人)至少有一个拥有此权限即可
find / -perm /6443. 指定文件最低权限查找,即大于等于
find / -perm -6444. 查找文件不是指定的权限(取反)
find / ! -perm 6445. 查找所有只读的文件
find . -perm /u=r6. 查找所有可执行文件
find . -perm /a=x-mmin n 查找按照分钟时间进行搜索
File's data was last modified less than, more than or exactly n minutes ago.-mtime n 按照多少天进行搜索
File's data was last modified less than, more than or exactly n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times. -prune需要和-path结合使用,并且放在其他条件前面通过文件的时间来查找
文件的时间分类:
访问时间 ( -atime/ 天, -amin/ 分钟):用户最近一次访问时间。修改时间 ( -mtime/ 天, -mmin/ 分钟):文件最后一次修改时间。变化时间 ( -ctime/ 天, -cmin/ 分钟):文件数据元(例如权限等)最后一次修改时间。1. 搜索最近七天内被访问过的所有文件
find . -type f -atime -72. 搜索恰好在七天前被访问过的所有文件
find . -type f -atime 73. 搜索超过七天内被访问过的所有文件
find . -type f -atime +74. 搜索访问时间超过10分钟的所有文件
find . -type f -amin +105. 找出比file.log修改时间更长的所有文件
find . -type f -newer file.log