列出不包含文件的目录

Ste*_*hen 7 find

我见过与此类似的问题,但我找不到与文件直接相关的任何内容。

有没有办法给我一个不包含特定文件的目录列表?

例子:

/dir1/good
/dir1/stuff
/dir2/junk
/dir2/morejunk
/dir3/good
/dir4/junk
Run Code Online (Sandbox Code Playgroud)

我想运行一个 find 命令,其中我只会返回不包含文件“good”(dir2 和 dir4)的目录名称。有什么办法可以用 find 或一些组合来做到这一点?我现在可以执行此操作的唯一方法是对文件“good”运行查找,保存该输出并使用一些 awk、sort 和 comm -3 命令来获取我需要的差异。

有没有更简单的方法来做到这一点?

use*_*517 7

您可以使用-exec test ...来检查目录中是否存在 good 文件,例如

find /path/to/search -type d \! -exec test -e '{}/good' \; -print
Run Code Online (Sandbox Code Playgroud)