按照路径及文件名查找文件:
命令格式:find 路径 -name 文件名
[root@localhost ~]# find /usr/test/ -name 2.txt
/usr/test/2.txt
[root@localhost ~]# find /usr/test/ -name *.txt
/usr/test/3.txt
/usr/test/2.txt
按照路径及文件类型查找文件:
命令格式:find 路径 -type 文件类型
[root@localhost ~]# find /dev/ -type f
[root@localhost ~]# find /dev/ -type d
[root@localhost ~]# find /dev/ -type s
[root@localhost ~]# find /dev/ -type b
[root@localhost ~]# find /dev/ -type c
搜索10天前(大于10天)创建的文件:
[root@localhost ~]# find /var/log/ -mtime +10
搜索10天内(小于10天)创建的文件:
[root@localhost ~]# find /var/log/ -mtime -10
[root@localhost ~]# find /var/log/ -mtime -365
搜索5分钟之前(大于5分钟)创建文件:
[root@localhost ~]# find /var/log/ -mmin +5
搜索5分钟之内(小于5分钟)创建文件:
[root@localhost ~]# find /var/log/ -mmin -5
组合使用:
[root@localhost ~]# find /usr/test/ -type f -name 1.txt
通过inode号搜索文件:
[root@localhost ~]# ls -li
912139 -rw-------. 1 root root 1098 Jul 31 07:18 anaconda-ks.cfg
912130 -rw-r--r--. 1 root root 9119 Jul 31 07:18 install.log
912131 -rw-r--r--. 1 root root 3091 Jul 31 07:17 install.log.syslog
[root@localhost ~]# find / -inum 912139
搜索一个月之前的日志:
[root@localhost ~]# find /var/log/ -type f -mtime +30
[root@localhost ~]# find /var/log/ -type f -mtime +30 |xargs rm
转载于:https://blog.51cto.com/blogfb/1894500