How to exclude a directory in find . command

后端 未结 30 1404
醉酒成梦
醉酒成梦 2020-11-22 03:36

I\'m trying to run a find command for all JavaScript files, but how do I exclude a specific directory?

Here is the find code we\'re using.<

30条回答
  •  旧巷少年郎
    2020-11-22 04:09

    find . \( -path '.**/.git' -o -path '.**/.hg' \) -prune -o -name '*.js' -print
    

    The example above finds all *.js files under the current directory, excluding folders .git and .hg, does not matter how deep these .git and .hg folders are.

    Note: this also works:

    find . \( -path '.*/.git' -o -path '.*/.hg' \) -prune -o -name '*.js' -print
    

    but I prefer the ** notation for consistency with some other tools which would be off topic here.

提交回复
热议问题