How to exclude a directory in find . command

helion3 picture helion3 · Nov 17, 2010 · Viewed 1.1M times · Source

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.

for file in $(find . -name '*.js')
do 
  java -jar config/yuicompressor-2.4.2.jar --type js $file -o $file
done

Answer

GetFree picture GetFree · Apr 1, 2013

If -prune doesn't work for you, this will:

find -name "*.js" -not -path "./directory/*"

Caveat: requires traversing all of the unwanted directories.