How to exclude a directory in find . command

后端 未结 30 1789
醉酒成梦
醉酒成梦 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 03:58

    Better use the exec action than the for loop:

    find . -path "./dirtoexclude" -prune \
        -o -exec java -jar config/yuicompressor-2.4.2.jar --type js '{}' -o '{}' \;
    

    The exec ... '{}' ... '{}' \; will be executed once for every matching file, replacing the braces '{}' with the current file name.

    Notice that the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation*.


    Notes

    * From the EXAMPLES section of the find (GNU findutils) 4.4.2 man page

提交回复
热议问题