[root@centos7 ~]# find . -name test.txt
[root@centos7 ~]# find / -name test.txt
/opt/test.txt
[root@centos7 ~]#
[root@centos7 ~]# find /opt -name "*.pdf"
[root@centos7 ~]# find /opt -type f -name "*.pdf"
通过指定 -type 选项来搜索其他类型的文件。
[root@centos7 ~]# find . -type d -name "test*"
[root@centos7 ~]#
[root@centos7 ~]# find . -type | -name "test*"
[root@centos7 ~]#
Linux 系统中的 3 个不同的时间戳:
[root@centos7 ~]# find . -type f -atime +365
./.bash_logout
./.cshrc
./.tcshrc
[root@centos7 ~]#
请不要包含 +,因为它的意思是“大于”
[root@centos7 ~]# find . -type f -mtime 5
[root@centos7 ~]#
find . -type f -ctime +5 -ctime -10
-size选项使我们能够按指定大小查找文件
b:512 字节块(默认)
c:字节
w:双字节字
k:KB
M:MB
G:GB
按时间戳查找文件,+ 表示“大于”,- 表示“小于”。例如,要查找大小为 10 MB ~ 1 GB 的文件:
find . -type f -size +10M -size -1G
find 命令的 -perm 选项可以帮助我们按指定权限查找文件:
[root@centos7 ~] find . -type f -perm 777
使用 -user 选项指定用户名:
[root@centos7 ~] find -type f -user test
[root@centos7 ~] find . -type f -atime +365 -exec rm -rf {} \;
上述命令在 -exec 选项后是 rm -rf,其用于删除文件。{} 是用于查找结果的占位符。
注意:占位符 {} 非常重要,尤其是在您想删除文件时。因为,如果您不使用它,该命令将对所有文件执行(而不是您刚刚通过 find 命令找到的文件)。