- 查找root目录下面以cfg结尾的文件
[root@localhost ~]# find /root/ -name '*cfg'
/root/anaconda-ks.cfg
/root/xuefei/e_file.cfg
/root/file.cfg
[root@localhost ~]# ll
drwxr-xr-x. 3 root root 21 1月 30 09:02 2018
-rw-------. 1 root root 1421 1月 22 17:16 anaconda-ks.cfg
-rw-------. 1 root root 1421 1月 30 09:06 file.cfg
drwxr-xr-x. 3 root root 67 2月 4 08:44 xuefei
- 查找root目录下面以cfg结尾的文件(忽略cfg大小写)
[root@localhost ~]# find /root/ -iname '*cfg'
/root/anaconda-ks.cfg
/root/xuefei/e_file.cfg
/root/file.cfg
/root/file.Cfg
[root@localhost ~]# find /root/ -name '*cfg'
/root/anaconda-ks.cfg
/root/xuefei/e_file.cfg
/root/file.cfg
[root@localhost ~]# ll
drwxr-xr-x. 3 root root 21 1月 30 09:02 2018
-rw-------. 1 root root 1421 1月 22 17:16 anaconda-ks.cfg
-rw-------. 1 root root 1421 1月 30 09:06 file.cfg
-rw-------. 1 root root 1421 2月 4 08:49 file.Cfg
drwxr-xr-x. 3 root root 67 2月 4 08:44 xuefei
- 查找root目录下面不以cfg结尾的文件(否定参数)
[root@localhost ~]# find /root/ ! -name "*cfg"
/root/
/root/.bash_logout
/root/xuefei/2018
/root/xuefei/2018/01
/root/xuefei/2018/01/29
/root/xuefei/2018/01/29/chmod_022.test
- 查找root目录下面文件(按照类型查找)
说明:f 普通文件 l 符号连接 d 目录 c 字符设备 b 块设备 s 套接字 p Fifo
[root@localhost ~]# find /root/ -type d
/root/
/root/.ssh
/root/xuefei
/root/xuefei/2018
/root/xuefei/2018/01
/root/xuefei/2018/01/29
- 查找root目录下面文件(最大深度为2)
说明:最大深度:-maxdepth 最小深度:-mindepth
[root@localhost ~]# find /root/ -maxdepth 2 -type d
/root/
/root/.ssh
/root/xuefei
/root/xuefei/2018
[root@localhost ~]# find /root/ -type d
/root/
/root/.ssh
/root/xuefei
/root/xuefei/2018
/root/xuefei/2018/01
/root/xuefei/2018/01/29
- 查找root目录修改时间在1天以内
访问时间(-atime/天, -amin/分钟):用户最近一次访问时间
修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间
变化时间(-ctime/天, -cmin/分钟):文件数据元(例如权限等)最后一次修改时间
[root@localhost ~]# find /root/ -mtime -1
/root/
/root/xuefei
/root/xuefei/e_file.cfg
/root/file.Cfg
[root@localhost ~]# ll /root/xuefei/e_file.cfg
-rw-------. 1 root root 1421 2月 4 08:44 /root/xuefei/e_file.cfg
- 查找root目录下10KB以内的文件
说明:b - 块(512字节) c - 字节 w - 字(2字节) k 千字节 M - 兆字节 G - 吉字节
[root@localhost ~]# find /root/ -size -10k
/root/
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/.bash_history
/root/.ssh
/root/.ssh/authorized_keys
/root/file.cfg
/root/.lesshst
/root/file.Cfg
[root@localhost ~]# ll
drwxr-xr-x. 3 root root 21 1月 30 09:02 2018
-rw-------. 1 root root 1421 1月 22 17:16 anaconda-ks.cfg
-rw-------. 1 root root 1421 1月 30 09:06 file.cfg
-rw-------. 1 root root 1421 2月 4 08:49 file.Cfg
- 查找root目录下所有长度为零的文件
[root@localhost ~]# find /root/ -empty
/root/xuefei/2018/01/29/chmod_022.test
/root/xuefei/cp.sh
/root/xuefei/chmod.text
/root/2018/mv_test/cp.sh
/root/2018/mv_test/xuefei/2018/01/29
/root/2018/mv_test/xuefei/cp.sh
[root@localhost ~]# ll /root/xuefei/2018/01/29/chmod_022.test
-rw-r--r--. 1 root root 0 2月 1 08:17 /root/xuefei/2018/01/29/chmod_022.test
[root@localhost ~]# cat /root/xuefei/2018/01/29/chmod_022.test
- 借助-exec选项与其他命令结合使用
[root@localhost ~]# find /root/ -empty -exec ls -l {} \;
-rw-r--r--. 1 root root 0 2月 1 08:17 /root/xuefei/2018/01/29/chmod_022.test
-rw-r--r--. 1 root root 0 1月 30 08:37 /root/xuefei/cp.sh
-rwxr--r--. 1 root root 0 2月 1 07:52 /root/xuefei/chmod.text
-rw-r--r--. 1 root root 0 1月 30 08:36 /root/2018/mv_test/cp.sh
-rw-r--r--. 1 root root 0 1月 30 08:45 /root/2018/mv_test/xuefei/cp.sh
- 查找root目录下所有长度为零的文件
[root@localhost ~]# find /root/ -type f -perm 777
/root/file.Cfg
[root@localhost ~]# ll
drwxr-xr-x. 3 root root 21 1月 30 09:02 2018
-rw-------. 1 root root 1421 1月 22 17:16 anaconda-ks.cfg
-rw-------. 1 root root 1421 1月 30 09:06 file.cfg
-rwxrwxrwx. 1 root root 1421 2月 4 08:49 file.Cfg
drwxr-xr-x. 3 root root 67 2月 4 08:44 xuefei