Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 查找路径中没有特定子文件夹的文件夹的路径_Regex_Bash - Fatal编程技术网

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

Regex 查找路径中没有特定子文件夹的文件夹的路径,regex,bash,Regex,Bash,假设我有以下文件夹结构: 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 i

假设我有以下文件夹结构:

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 . -type d -path '*/test' -not -path '*/c/*'
查找
命令详细信息:

  • :从当前路径匹配
  • -类型d
    :仅目录
  • -path'*/test'
    :匹配最后有
    /test
    的路径
  • -not-path'*/c/*'
    :但中间没有
    /c/

    • 您可以使用此
      查找

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

      • :从当前路径匹配
      • -类型d
        :仅目录
      • -path'*/test'
        :匹配最后有
        /test
        的路径
      • -not-path'*/c/*'
        :但中间没有
        /c/

      OP可以使用
      而不是
      -不
      来创建:
      查找-类型d-路径“*/test”-路径“*/c/*”
      你怎么说它不可移植?我能在我的windows和linux计算机上运行这个吗?您可以使用
      而不是
      -不
      来创建:
      查找-类型d-路径“*/test”-路径“*/c/*”
      你怎么说它不可移植?我能在我的windows和linux计算机上运行这个吗?谢谢