find其他技巧收集
1.要列出所有长度为零的文件: find . -empty
2.在/home目录下查找以.txt结尾的文件名: find /home -name "*.txt"
3.在/home目录下查找以.txt结尾的文件名(忽略大小写): find /home -iname "*.txt"
4.当前目录及子目录下查找所有以.txt和.pdf结尾的文件
find . \( -name "*.txt" -o -name "*.pdf" \)
或
find . -name "*.txt" -o -name "*.pdf"
5.基于正则表达式匹配文件路径
[hduser0401@dev-l002782 test]$ touch 1.txt
[hduser0401@dev-l002782 test]$ touch 2.log
[hduser0401@dev-l002782 test]$ touch 3.pdf
[hduser0401@dev-l002782 test]$ touch 4.TXT
[hduser0401@dev-l002782 test]$ touch 5.PDF
[hduser0401@dev-l002782 test]$ find . -regex ".*\(\.txt|\.pdf\)"
[hduser0401@dev-l002782 test]$ find . -regex ".*\(\.txt\|\.pdf\)"
./3.pdf
./1.txt
[hduser0401@dev-l002782 test]$ find . -iregex ".*\(\.txt\|\.pdf\)" --忽略大小写
./5.PDF
./3.pdf
./4.TXT
./1.txt
[hduser0401@dev-l002782 test]$
6.找出/home下不是以.txt结尾的文件: find /home ! -name "*.txt"
7.UNIX/Linux文件系统每个文件都有三种时间戳:
访问时间(-atime/天,-amin/分钟):用户最近一次访问时间。
修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间。
变化时间(-ctime/天,-cmin/分钟):文件数据元(例如权限等)最后一次修改时间。
搜索最近七天内被访问过的所有文件
find . -type f -atime -7
搜索恰好在七天前被访问过的所有文件
find . -type f -atime 7
搜索超过七天内被访问过的所有文件
find . -type f -atime +7
搜索访问时间超过10分钟的所有文件
find . -type f -amin +10
找出比file.log修改时间更长的所有文件
find . -type f -newer file.log
根据文件大小进行匹配
find . -type f -size 文件大小单元