find使用教程

find 命令可以用来查找文件和目录
find 的一般格式为: find 查找范围 查找条件

按名称查找

1
2
3
[root@ceph-node3 ~]# find /etc/ -name *net.conf
/etc/sane.d/dell1600n_net.conf
/etc/sane.d/net.conf

按深度查找

最大深度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@ceph-node3 ~]# find /etc -maxdepth 1 -name *.conf
/etc/resolv.conf
/etc/sos.conf
/etc/libuser.conf
/etc/idmapd.conf
/etc/logrotate.conf
/etc/request-key.conf
/etc/host.conf
/etc/mke2fs.conf
/etc/mtools.conf
/etc/e2fsck.conf
/etc/yum.conf
/etc/man_db.conf
/etc/dracut.conf
/etc/ld.so.conf
/etc/nsswitch.conf
/etc/krb5.conf
/etc/libaudit.conf
/etc/asound.conf
/etc/fuse.conf

最小深度

1
2
3
4
5
[root@ceph-node3 ~]# find /etc -mindepth 4 -name *.conf
/etc/X11/xinit/xinput.d/none.conf
/etc/X11/xinit/xinput.d/xcompose.conf
/etc/X11/xinit/xinput.d/xim.conf
/etc/X11/xinit/xinput.d/ibus.conf

按用户查找

1
2
3
[root@ceph-node3 ~]# find /etc -user root  -name *net.conf
/etc/sane.d/dell1600n_net.conf
/etc/sane.d/net.conf

按文件大小查找

小于20k

1
2
3
[root@ceph-node3 ~]# find /etc -size -20k  -name *net.conf
/etc/sane.d/dell1600n_net.conf
/etc/sane.d/net.conf