代码之家  ›  专栏  ›  技术社区  ›  alvatar

shell或regex中“匹配除这些字符串以外的所有内容”的最紧凑版本是什么?

  •  4
  • alvatar  · 技术社区  · 17 年前

    Linux:我想列出一个目录及其子目录中的所有文件,除了一些字符串。为此,我一直在使用find/grep/shell globbing的组合。例如,我想列出除目录中的文件以外的所有文件

    ./bin
    ./lib
    ./resources
    

    我理解这可以如图所示完成 in this question 和 this other . 但这两个版本并不能解决“一切,但这一模式”的一般问题。

    谢谢

    3 回复  |  直到 9 年前
        1
  •  7
  •   flybywire    17 年前

    yourcommand | egrep -v "pattern1|pattern2|pattern3"

        2
  •  6
  •   vartec    17 年前

    使用find的prune选项。

    find . -path './bin' -prune -o -path './lib' -prune -o -path './resources' -prune -o «rest of your find params» 
    
        3
  •  3
  •   Rob Kennedy    17 年前

    具有 bash's extglob shopt setting ! 在你的 wildcard pattern . 一些例子:

    • shopt -s extglob
      ls -Rl !(bin|lib|resources)
      
    • 一切都有一个 i

      ls -Rl !(bin|lib|!(*i*))
      

      (每件有 我 在这里,一切都是一样的 除了 那些 不要 有 我 (在他们里面。)