我试图查找所有日期为 3 天或更早的文件。
find /home/test -name 'test.log.\d{4}-d{2}-d{2}.zip' -mtime 3
它没有列出任何东西。有什么问题吗?
最佳答案
find /home/test -regextype posix-extended -regex '^.*test\.log\.[0-9]{4}-[0-9]{2}-[0-9]{2}\.zip' -mtime +3
-name
使用globular 表达式, 又名通配符。你想要的是-正则表达式
- 要按照您的意愿使用间隔,您
需要告诉
find
使用 Extended 正则表达式 通过-regextype posix-extended
标志 - 你需要避开经期
因为在正则表达式中,句点有
任何单曲的特殊含义
字符。你想要的是一个
由
\.
表示的字面句点
- 只匹配那些文件
大于 3 天,您需要在号码前加上
+
作为前缀 在-mtime +3
中。
概念验证
$ find . -regextype posix-extended -regex '^.*test\.log\.[0-9]{4}-[0-9]{2}-[0-9]{2}\.zip'
./test.log.1234-12-12.zip
关于bash - 如何使用 "find"通过正则表达式搜索文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5249779/