我已尝试执行以下命令 find 。 | egrep -v '.*/[A-Z]{3}-[0-9]{8}-.'
递归搜索不在模式中的文件(不是文件夹)。这也显示文件夹!我错过了什么?
最佳答案
您可以直接使用 find
和 -not
选项:
find . -type f -regextype posix-egrep -not -regex '.*/[A-Z]{3}-[0-9]{8}-[^/]*$' -exec basename {} \;
通过 GNU find
,您可以使用
find . -type f -regextype posix-egrep -not -regex '.*/[A-Z]{3}-[0-9]{8}-[^/]*$' -printf "%f\n"
详细信息:
-type f
- 仅返回文件路径-regextype posix-egrep
将正则表达式风格设置为 POSIX ERE-not
反转正则表达式结果.*/[A-Z]{3}-[0-9]{8}-[^/]*$
- 匹配文件名以三个大写字母开头的路径,-
、八位数字、-
,然后可以包含除/
之外的任何文本,直到字符串末尾-exec basename {}\;
/-printf "%f\n"
仅打印不带文件夹的文件名(参见 Have Find print just the filenames, not full paths )
关于基于文件名的 Linux 文件系统正则表达式搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71525975/