【问题标题】:How to exclude multiple subdirectories when using "find" command?使用“查找”命令时如何排除多个子目录?
【发布时间】:2017-05-14 08:43:29
【问题描述】:

我正在寻找“*.py”文件,并排除“build”和“bin”目录。我使用了这个命令:

find * -path "build" -prune -path "bin" -prune -o -type f \( -name "*.py" \) -print > findpyfiles.txt

“findpyfiles.txt”仍然包含以“bin/”开头的结果。 如何解决?

【问题讨论】:

标签: linux path find subdirectory


【解决方案1】:

虽然这个问题在其他地方有答案,但可能值得知道为什么您的命令无法正常工作:您在 -path "build" -prune-path "bin" -prune@ 之间省略了一个 运算符假设 987654323@ 省略了运算符,因此当 -path "build" 返回 false 时不会评估 -path "bin"。显式指定 OR 运算符修复它,要么

find * -path build -prune -o -path bin -prune -o -type f -name "*.py" -print >findpyfiles.txt

find * \( -path build -o -path bin \) -prune -o -type f -name "*.py" -print >findpyfiles.txt

【讨论】:

    猜你喜欢
    • 2015-06-27
    • 2019-10-08
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2012-08-27
    • 2011-05-11
    • 2016-05-22
    • 1970-01-01
    相关资源
    最近更新 更多