find命令常用场景

1、查找/var目录下属主为root并且属组为mail的所有文件;

 find /var -user root -group mail 


2、查找/usr目录下不属于root,bin,或student的文件;

find /usr -not -user root -a -not -user bin -a -not -user student
find /usr -not ( -user root -o -user bin -o -user student )


3、查找/etc目录下最近一周内内容修改过且不属于root及student用户的文件;

find /etc -mtime -7 -a -not ( -user root -o -user student ) -exec stat {} ;


4、查找当前系统上没有属主或属组且最近1天内曾被访问过的文件,并将其属主属组均修改为root;

find / (-nouser -o -nogroup ) -a -atime -1 -exec chown root.root {} ;


5、查找/etc目录下大于1M的文件,并将其文件名写入/tmp/etc.largefiles文件中;

find /etc -size +1M -exec echo {} >> /tmp/etc.largefiles ;


6、查找/etc目录下所有用户都没有写权限的文件,显示出其详细信息;

find /etc -not -perm /222 -ls
原文地址:https://www.cnblogs.com/ElegantSmile/p/11360346.html