find查找高级应用
一、根据文件属性查找
(一)忽略文件名大小写
根据名称查找,忽略大小写
-iname
[root@localhost ~]# find /etc/ -iname "network*"
/etc/sysconfig/network-scripts
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/sysconfig/network-scripts/network-functions
/etc/sysconfig/network
/etc/networks
/etc/systemd/system/multi-user.target.wants/NetworkManager.servic
/etc/systemd/system/network-online.target.wants
/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service
/etc/rc.d/init.d/network
/etc/selinux/targeted/active/modules/100/networkmanager
/etc/libvirt/qemu/networks
/etc/vmware-tools/scripts/vmware/network
/etc/NetworkManager
/etc/NetworkManager/NetworkManager.conf
(二)指定文档归属
根据账号名称或ID查找
-uid(标识用户)、-gid(标识组)、-user、-group
-nouser、-nogroup
[root@localhost ~]# find /dev/ -group cdrom
/dev/sg1
/dev/sr0
[root@localhost ~]# ls -lh /dev/{sg1,sr0}
crw-rw----+ 1 root cdrom 21, 1 7月 1 21:54 /dev/sg1
brw-rw----+ 1 root cdrom 11, 0 7月 1 21:54 /dev/sr0
[root@localhost ~]# id deer-fish
uid=1000(deer-fish) gid=1000(deer-fish) 组=1000(deer-fish),10(wheel)
[root@localhost ~]# find /home/ -uid 1000
/home/deer-fish
/home/deer-fish/文档
/home/deer-fish/.bash_history
/home/deer-fish/.cache
/home/deer-fish/.cache/gnome-software
/home/deer-fish/.cache/gnome-software/odrs
/home/deer-fish/.cache/gnome-software/shell-extensions
/home/deer-fish/.cache/gstreamer-1.0
/home/deer-fish/.cache/gstreamer-1.0/registry.x86_64.bin
/home/deer-fish/.cache/abrt
……
(三)指定文档i节点编号
同一个文件系统内文件的i节点编号具有唯一性
当文件名存在乱码等现象时,方便定位文档
-inum
[root@localhost ~]# touch /data/text01.txt
[root@localhost ~]# ls /data
text01.txt
[root@localhost ~]# ls -i /data/text01.txt
11 /data/text01.txt
[root@localhost ~]# find /data/ -inum 11
/data/text01.txt
二、限制查找深度
(一)最多查到第几层目录
从指定目录(第1层)查找,最多深入到第x层目录
-maxdepthx层
[root@localhost ~]# find /etc -maxdepth 2 -name "res*"
/etc/resolv.conf.save
/etc/vmware-tools/resume-vm-default
/etc/resolv.conf
(二)最少从第几层目录查找
从指定目录(第1层)查找,最多深入到第x层目录
-maxdepthx层
[root@localhost ~]# find /etc -mindepth 2 -name "res*"
/etc/vmware-tools/resume-vm-default