Linux教程

find:用于查找符合条件的文件或目录

2019-12-13  本文已影响0人  7ed8e3680ebe

Linux教程:http://www.fdlly.com/m/linux
本文介绍linux的find命令功能说明、语法、选项与参数、使用详解,并演示如何使用find命令在linux上查找文件或目录

find命令用于用于查找符合条件的文件,它会去保存文件与目录名称的数据库内,查找合乎范本样例条件的文件或目录

find:用于查找符合条件的文件或目录

功能说明:用于查找符合条件的文件或目录
语法:

find [参数] [名称]

选项与参数:

实例

按名字查找

# 在当前目录及子目录中,查找大写字母开头的txt文件
[root@localhost /]# find . -name "[A-Z]*.txt" -print

#在/etc及其子目录中,查找host开头的文件 
[root@localhost ~]# find /etc -name "host*" -print

#在$HOME目录及其子目录中,查找所有文件
[root@localhost ~]# find ~ name"*" -print

按权限查找

#在当前目录及子目录中,查找属主具有读写执行,其他具有读执行权限的文件   
[root@localhost /]# find . -perm 755 -print

按类型查找

#在当前目录及子目录下,查找符号链接文件
[root@localhost /]# find . -type | -print

按属主及属组

#查找属主是www的文件   
[root@localhost /]# find / -user www -type f -print

#查找属主被删除的文件 
[root@localhost /]# find / -nouser -type f -print

#查找属组 mysql 的文件 
[root@localhost /]# find / -group mysql -type f -print

#查找用户组被删掉的文件 
[root@localhost /]# find / -nogroup -type f -print

按时间查找

#查找2天内被更改过的文件 
[root@localhost /]# find . -mtime -2 -type f -print

#查找2天前被更改过的文件 
[root@localhost /]# find . -mtime +2 -type f -print

#查找一天内被访问的文件 
[root@localhost /]# find . -atime -1 -type f -print

#查找一天前被访问的文件
[root@localhost /]# find . -atime +1 -type f -print

#查找一天内状态被改变的文件
[root@localhost /]# find . -ctime -1 -type f -print

#查找一天前状态被改变的文件 
[root@localhost /]# find . -ctime +1 -type f -print

#查找10分钟以前状态被改变的文件
[root@localhost /]# find . -cmin +10 -type f -print

按文件新旧

#查找比 aa.txt 新的文件 
[root@localhost /]# find . -newer "aa.txt" -type f -print   

#查找比 aa.txt 旧的文件 
[root@localhost /]# find . ! -newer "aa.txt" -type f -print   

#查找比aa.txt新,比bb.txt旧的文件 
[root@localhost /]# find . -newer 'aa.txt' ! -newer 'bb.txt' -type f -print 

按大小查找

#查找超过1M的文件 
[root@localhost /]# find / -size +1M -type f -print   

#查找等于6字节的文件 
[root@localhost /]# find . -size 6c -print   

#查找小于32k的文件 
[root@localhost /]# find . -size -32k -print 

上一篇 下一篇

猜你喜欢

热点阅读