说我有这个文件夹结构:
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上是否都可以兼容,和/或这是否是“好”方式。
你会怎么做?
您可以使用find
:
find . -type d -path '*/test' -not -path '*/c/*'
find
命令详细信息:
.
:从当前路径匹配-type d
:仅目录-path '*/test'
:匹配/test
末尾的路径-not -path '*/c/*'
:但/c/
中间不要有任何地方本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句