find的使用方式

find的参数格式是
find 查找位置 查找类型 执行动作
find / -name passwd -ls
上面命令就是在根目录查找一个名字为passwd的文件,并且显示出来
查找tmp目录下没有属主或没有属组的文件,显示出来
find /tmp (-nouser -o -nogroup) -ls
查找tmp目录下没有属主而且没有属组的文件,显示出来
find /tmp (-not -name ‘fstab’ -a -not -user root) -ls
查找tmp目录下大小在25-26k的目录,显示出来
find /tmp -size 26k -ls
查找tmp目录下大小在0-25k的目录,显示出来
find /tmp -size -26k -ls
查找tmp目录下大小在26k以上的目录,显示出来
find /tmp -size +26k -ls
精确查找权限
find /etc -perm 600 -ls
查找只要属主、属组和其他用户,只要和一个符合权限的文件
find /tmp -perm /+222 -ls
查找每一类对象都必须最少拥有为其指定的权限标准
find /tmp -perm /+222 -ls
处理动作:
-print :默认的处理动作,显示到屏幕
-ls 类似于对查找到的文件执行"ls -l"命令
-fls /path 查找到的所有文件的长格式信息保存到指定的文件中
-exec COMMAND {} ;对查找到的每一个文件执行由COMMAND指定的命令
{}用于引用查找到的名称
find传递查找的文件至后面指定的命令时,查找到所有符合条件的文件一次性传递给后面的命令:可是有的命令不能接受太多的参数 ,此时命令执行就可能会失败,另一种 方式可规避此问题
find /tmp/ -size +1k | xargs ls -lh

-atime +3 三天之前做过访问的
-mtime -3 三天之内做过修改的
-ctime 3 满三天不到四天做过改变的

-amin就是分钟 ,-atime 就是天

答案
find /var -user root -a -group mail -ls
find /usr/ -not ( -user root -o -user bin -o -user hadoop ) -ls
find /etc/ -mtime -7 -a -not ( -user root -o user hadoop ) -ls
find / -nouser -nogroup -a -atime -7
find /etc/ -size +1M -a -type f -ls
find /tmp/ -not -perm /222 -ls
find /tmp/ -not -perm -111
find /etc/init.d/ -perm -511

猜你喜欢

转载自blog.csdn.net/hn8081com/article/details/82866282