你可能认为我已经可以在某个地方找到这个问题的答案,但我正在努力这样做。我想找到一些名称类似于
的日志文件myfile_3.log
但是我只想找到数字在一定范围内的那些。我试过这样的事情:
find <path> -name myfile_{0..67}.log #error: find: paths must precede expression
find <path> -name myfile_[0-67].log #only return 0-7, not 67
find <path> -name myfile_[0,67].log #only returns 0,6,7
find <path> -name myfile_*([0,67]).log # returns only 0,6,7,60,66,67,70,76,77
还有其他想法吗?
最佳答案
如果您想使用正则表达式匹配整数范围,请在您的find
命令中使用选项-regex
。
例如,要匹配从 0 到 67 的所有文件,请使用:
find <path> -regextype egrep -regex '.*file([0-5][0-9]|6[0-7])\.txt'
正则表达式有两部分:
[0-5][0-9]
匹配范围 0-596[0-7]
匹配范围 60-67
请注意选项 -regextype egrep
以扩展正则表达式。
还要注意选项 -regex
匹配整个文件名,包括路径,这就是 .*
在正则表达式开头的原因。
关于linux - “查找”包含指定范围内整数的文件(在 bash 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51893233/