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

[root@bogon ~]# find /var -user root -a -group mail
/var/spool/mail
/var/spool/mail/root

注意: find /var -user root -group mail也可返回同样的结果。两个查询条件在默认情况下是逻辑与

find /var -user root -a -group mail -exec ll {} \;

会提示错误。需要使用ls -l才行


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

find /usr \! -user root -a  \! -user bin -a  \! -user testcai

find /usr -not -user root -a -not -user bin -a -not -user testcai

或者根据的摩根律

find /usr -not \( -user root -o -user bin -o -user testcai  \)

都是正确的。

需要注意:

    -not 和 \!是一个含义。

    -not 逻辑非,-o 逻辑或,-a 逻辑与

    对 ! ()在find中需要使用转移字符\


3、查找/etc 目录下最近一周内修改切不属于root及testcai用户的文件

    find /etc -mtime +7 -a -not \( -user root -o -user testcai \)

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

[root@bogon testdir]# find /tmp/testdir/ \( -nouser -o -nogroup \) -a -atime +1 -exec chown root. {} \;

 find命令的格式 find 路径 条件 操作对象 处理动作。

其中 {} \; 是必不可少的。且 {} 代表的是find查找到的结果。


5、查找/etc下大于1M的文件,并将其文件名写入到到/tmp/etclarge.file

[root@bogon testdir]# find /etc -size +1M -exec ls {} > /tmp/.etclarge.file \;
[root@bogon testdir]# cat /tmp/.etclarge.file
/etc/gconf/gconf.xml.defaults/%gconf-tree.xml
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern

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

[root@bogon testdir]# find /etc -not -perm /222 -ls