regex - 如何在 Linux 中将正则表达式传递给 find 命令?

标签 regex linux bash ubuntu

当我输入命令时

查找 ./-iname "*.pdf"查找 ./-iname\*.pdf

列出当前文件夹树下的所有 pdf 文件。 同样,

查找./-iname "*.doc"

列出所有文档文件。

我的问题是如何列出这两种类型的文件?我尝试了像

这样的命令

查找 ./-iname "*.{pdf,doc}"

但这不起作用。

最佳答案

使用 glob,您可以使用 -o (OR)`:

find . \( -iname "*.pdf" -o -iname "*.doc" \)

或者使用正则表达式:

find . -regextype posix-extended -regex '.*\.(pdf|doc)$'

在 OSX 上查找使用:

find -E . -regex '.*\.(pdf|doc)$'

关于regex - 如何在 Linux 中将正则表达式传递给 find 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32728250/

相关文章:

javascript - Javascript正则表达式将新行添加到匹配项中

java - 替换多次出现的字符

linux - 复制带扩展名的文件并按文件名排除

python - 如何在 Linux centos 中将 celeryd 作为 django 的守护进程

bash - 在 bashrc 中为 GREP_OPTIONS 匹配文件类型 --exclude

bash - 将文件分割成多个子文件

javascript - 正则表达式循环问题

c# - 在 C# 中使用 .matches .Concat 进行正则表达式和正确捕获

Linux内核模块相关的理解?

linux - 在基于 linux 的集群 : matlab sessions stops before m file is completly executed 上调用 Matlab