查找路径中没有特定子文件夹的文件夹的路径

说我有这个文件夹结构:

a/b/test/
a/b/c/test/
a/b/d/test/

我想编写一个返回以下内容的bash脚本:

a/b/test/
a/b/d/test/

目前,我正在尝试find

find . -regex ".*/test",但这会返回所有内容。

find . -regex "[^c]"这什么都不返回

我想要的是find . -regex "(?!c)"之类的东西,但是我无法在bash中使用回溯

我也可以做类似的事情

if [[${pwd} == *"c"*]]; then
    dont include in output
fi

但是在最后一个示例中,我不确定这在Linux和Windows上是否都可以兼容,并且/或者这是否是“好”方式。

你会怎么做?

liaojiie 回答:查找路径中没有特定子文件夹的文件夹的路径

您可以使用此0

find

find . -type d -path '*/test' -not -path '*/c/*' 命令详细信息:

  • find:从当前路径匹配
  • .:仅目录
  • -type d:匹配结尾为-path '*/test'的路径
  • /test:但是中间没有-not -path '*/c/*'
本文链接:https://www.f2er.com/3151163.html

大家都在问