我有一个像这样的查找命令:
find /root/newdir/ -mindepth 1 -maxdepth 1 -type f
像这样的输出:
/root/newdir/test.log
/root/newdir/test2.log
/root/newdir/tmp_test3.log
/root/newdir/test.zip
我需要找到开始test
和结束的文件.log
。有时我也需要复杂的正则表达式。我尝试-regex
像这样的示例,但不起作用:
find /root/newdir/ -mindepth 1 -maxdepth 1 -type f -regex "^test*.log$"
如何^ $
在find命令中使用正则表达式之类的字符?
例如,由于输出为/path/to/file/test2.log,因此您不能使用^,因为该行的开头应类似于/ path / to / file。
在这种情况下,您可以执行以下操作:
find . -mindepth 1 -maxdepth 1 -type f -regex ".*/temp[^\/]*log$"
现在,您只能在last /之后加上所需的正则表达式来查找文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句