41. find

Date:

2018-09

41.1. 命令格式

41.2. 所属用户

41.3. 使用指导

41.4. 参数

41.5. 参考实例

41.5.1. 根据用户和组信息查找文件

查找/var目录属主为root且属组为mail的所有文件:
1[root@zzjlogin ~]# find /var/ -user root -group mail
2/var/spool/mail
3[root@zzjlogin ~]# ll -d /var/spool/mail
4drwxrwxr-x. 2 root mail 4096 9月  23 2011 /var/spool/mail
查找/usr目录下不属于root,bin的文件:
1[root@zzjlogin ~]# find /usr/ -not \( -user root -o -user bin \)
2/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

41.5.2. 根据访问时间找文件

查找/etc/目录下最近一周内其内容修改过的,且不属于bin且不属于ntp:
1[root@zzjlogin ~]# find /etc/ -mtime -7 -not -user bin -not -user ntp
2/etc/
3/etc/resolv.conf
4/etc/mtab
5/etc/adjtime
6/etc/prelink.cache

41.5.3. 根据文件大小查找文件

查找/etc/目录不大于1M且类型为普通文件的所有文件,然后统计文件个数:
1[root@zzjlogin ~]# find /etc/ -size -$[1*1024*1024] -type f | wc -l
2944

41.5.4. 根据文件权限查找文件

查找/etc/目录所有用户都没有写权限的文件
 1[root@zzjlogin ~]# find /etc/ -not -perm /222 -ls
 230683    4 -r-xr-xr-x   1 root     root         1340 10月 16  2014 /etc/rc.d/init.d/blk-availability
 330685    4 -r-xr-xr-x   1 root     root         2757 10月 16  2014 /etc/rc.d/init.d/lvm2-monitor
 430684    4 -r-xr-xr-x   1 root     root         2134 10月 16  2014 /etc/rc.d/init.d/lvm2-lvmetad
 512334  236 -r--r--r--   1 root     root       240762 3月 30 17:34 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
 612336  188 -r--r--r--   1 root     root       191772 3月 30 17:34 /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
 712335  188 -r--r--r--   1 root     root       191741 3月 30 17:34 /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
 812333  316 -r--r--r--   1 root     root       321332 3月 30 17:34 /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
 912337  176 -r--r--r--   1 root     root       179212 3月 30 17:34 /etc/pki/ca-trust/extracted/java/cacerts
1029174    4 -r--r--r--   1 root     root          324 10月 15  2014 /etc/ld.so.conf.d/kernel-2.6.32-504.el6.x86_64.conf
1130679    4 -r--r--r--   1 root     root         2231 10月 16  2014 /etc/lvm/profile/command_profile_template.profile
1230681    4 -r--r--r--   1 root     root           76 9月  1  2014 /etc/lvm/profile/thin-generic.profile
1330682    4 -r--r--r--   1 root     root           80 9月  1  2014 /etc/lvm/profile/thin-performance.profile
1430680    4 -r--r--r--   1 root     root          827 10月 16  2014 /etc/lvm/profile/metadata_profile_template.profile
1531662    4 ----------   1 root     root          469 3月 30 17:39 /etc/gshadow
16129205    4 -r--------   1 root     root           45 3月 30 17:35 /etc/openldap/certs/password
1731587    4 -r--r-----   1 root     root         4002 3月  2  2012 /etc/sudoers
18613    4 ----------   1 root     root          699 3月 30 17:41 /etc/shadow-
19130    4 ----------   1 root     root          691 3月 30 17:44 /etc/shadow
查找/etc/init.d目录下,所有用户都有执行权限,且其他用户有写权限的文件
1[root@zzjlogin ~]# find /etc/init.d/ -perm -113
查找/etc目录下只有一类用户没有写权限的文件
1[root@zzjlogin ~]# find /etc/  \( -perm -220 -o -perm -202 -o -perm -022 \) -not -perm -222

41.6. 相关命令