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

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

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


当前回答

find . ! \( -name "*.exe" -o -name "*.dll" \)

其他回答

你可以使用grep命令做一些事情:

find . | grep -v '(dll|exe)$'

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

find  /data1/batch/source/export   -type f -not  -name "*.dll" -not -name "*.exe"

还有一个:-)

$ ls -ltr
total 10
-rw-r--r--    1 scripter     linuxdumb         47 Dec 23 14:46 test1
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:40 test4
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:40 test3
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:40 test2
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:41 file5
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:41 file4
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:41 file3
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:41 file2
-rw-r--r--    1 scripter     linuxdumb          0 Jan  4 23:41 file1
$ find . -type f ! -name "*1" ! -name "*2" -print
./test3
./test4
./file3
./file4
./file5
$

Unix查找命令参考

find . ! \( -name "*.exe" -o -name "*.dll" \)
$ find . -name \*.exe -o -name \*.dll -o -print

前两个name选项没有-print选项,所以跳过了。其他的都打印出来了。