根据指定的条件在指定目录下搜索
−用法:find [查找范围] [查找条件]
−递归式查找,未指定范围时,默认从当前目录下查找
用法:-type 类型
−普通文件f、目录d、快捷方式l
−块设备b、字符设备c
- [root@hadoop opt]# ls -lh /boot/grub/menu.lst
- lrwxrwxrwx. 1 root root 11 Nov 16 19:35 /boot/grub/menu.lst -> ./grub.conf
- [root@hadoop opt]# find /boot -type d //查找目录
- /boot
- /boot/efi
- /boot/efi/EFI
- /boot/efi/EFI/redhat
- /boot/grub
- /boot/lost+found
用法:-name "名称"
−允许*、?、[ ] 通配符,名称以双引号括起来
组合多个条件时:-a:而且,为缺省项;-o:或者
- [root@hadoop opt]# find /etc -name "resol*.conf"
- /etc/resolv.conf
- [root@hadoop opt]# find /dev -type c -a -name "*y[1-3]"
- /dev/tty3
- /dev/tty2
- /dev/tty1
用法:-size [+|-]大小
+ 超过多大、-低于多大
- [root@hadoop opt]# find /boot -size +10M
- /boot/initramfs-2.6.32-431.el6.x86_64.img
- [root@hadoop opt]# ls -lh /boot/initramfs-2.6.32-431.el6.x86_64.img
- -rw-------. 1 root root 16M Nov 16 19:35 /boot/initramfs-2.6.32-431.el6.x86_64.img
用法:-mtime[+|-]天数
+ n天之前、-n天之内
输出的信息有限
−仅列出文档所在的路径及名称
−默认情况下,不会做进一步的处理操作
- [root@hadoop opt]# find /boot -size +3M
- /boot/initramfs-2.6.32-431.el6.x86_64.img
- /boot/vmlinuz-2.6.32-431.el6.x86_64

- [root@hadoop opt]# find /boot -size +3M | wc -l
- 2
- [root@hadoop opt]# ls -lh $(find /boot -size +3M)
- -rw-------. 1 root root 16M Nov 16 19:35 /boot/initramfs-2.6.32-431.el6.x86_64.img
- -rwxr-xr-x. 1 root root 4.0M Nov 22 2013 /boot/vmlinuz-2.6.32-431.el6.x86_64
避免因参数太多导致异常
−用法:find .. .. -exec 处理命令{} \;
−其中{} 替代每一个查找结果,\; 表示处理操作结束
- [root@hadoop opt]# find /boot -size +3M -exec ls -lh {} \;
- -rw-------. 1 root root 16M Nov 16 19:35 /boot/initramfs-2.6.32-431.el6.x86_64.img
- -rwxr-xr-x. 1 root root 4.0M Nov 22 2013 /boot/vmlinuz-2.6.32-431.el6.x86_64
根据名称查找,忽略大小写
−-iname
- [root@hadoop opt]# find /etc/ -iname "network"
- /etc/sysconfig/network
- /etc/rc.d/init.d/network
根据账号名称或ID查找
−-uid、-gid、-user、-group
−-nouser、-nogroup
- [root@hadoop opt]# find /dev/ -group cdrom
- /dev/sg0
- /dev/sr0
- [root@hadoop opt]# ls -lh /dev/{sg1,sr0}
- crw-rw----. 1 root disk 21, 1 Apr 20 11:50 /dev/sg1
- brw-rw----. 1 root cdrom 11, 0 Apr 20 11:50 /dev/sr0
同一个文件系统内文件的i节点编号具有唯一性
−当文件名存在乱码等现象时,方便定位文档
−-inum
- [root@hadoop opt]# ls -li install.log*
- 397986 -rw-r--r--. 1 root root 9458 Nov 16 19:35 install.log
- [root@hadoop opt]# find ./ -inum 397986
- ./install.log
从指定目录(第1层)查找,最多深入到第x层目录
−-maxdepthx层
- [root@hadoop opt]# find /etc -maxdepth 2 -name "res*.conf"
- /etc/resolv.conf
- /etc/selinux/restorecond_user.conf
- /etc/selinux/restorecond.conf //第3层目录及往下子目录不会被查找
从第x层目录开始查找,略过少于x层的目录
−-mindepthx层
- [root@hadoop opt]# find /etc -mindepth 2 -name "res*.conf"
- /etc/selinux/restorecond_user.conf
- /etc/selinux/restorecond.conf //第1层目录不会被查找