UNIX查找找到不以特定扩展名结尾的文件名?

Cri*_*scu 195 command-line find

是否有一种简单的方法来递归查找目录层次结构中的所有文件,这些文件以扩展列表结尾?例如,所有不是*.dll或*.exe的文件

UNIX/GNU查找,功能强大,似乎没有exclude模式(或者我错过了它),而且我总是发现很难使用正则表达式来查找与特定表达式匹配的内容.

我在Windows环境中(使用大多数GNU工具的GnuWin32端口),所以我同样对Windows解决方案开放.

Har*_*rdy 323

或者没有(并且需要逃脱它:

find . -not -name "*.exe" -not -name "*.dll"
Run Code Online (Sandbox Code Playgroud)

并且还排除目录列表

find . -not -name "*.exe" -not -name "*.dll" -not -type d
Run Code Online (Sandbox Code Playgroud)

或者是积极的逻辑;-)

find . -not -name "*.exe" -not -name "*.dll" -type f
Run Code Online (Sandbox Code Playgroud)

  • `-not`可以替换为''!'`(推荐引用).另一方面,`-name`区分大小写,而`-iname`不区分大小写. (5认同)

Che*_*evy 44

find . ! \( -name "*.exe" -o -name "*.dll" \)
Run Code Online (Sandbox Code Playgroud)

  • 在Solaris`-not`是一个糟糕的选择,这个用`!`很好用:) (2认同)

Jef*_*and 8

$ find . -name \*.exe -o -name \*.dll -o -print
Run Code Online (Sandbox Code Playgroud)

前两个-name选项没有-print选项,因此它们被跳过.其他一切都打印出来了.


Vot*_*ple 6

您可以使用 grep 命令执行某些操作:

find . | grep -v '(dll|exe)$'
Run Code Online (Sandbox Code Playgroud)

上的-v标志grep特别表示“查找与此表达式匹配的内容”。

  • grep -v '\.(dll|exe)$' 将阻止匹配名为“dexe”的文件或目录,例如 (7认同)
  • 这仅适用于扩展正则表达式。我必须添加 -E (或使用egrep)才能完成这项工作。 (2认同)