Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a directory in find . command

Tags:

linux

find

shell

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 
like image 813
helion3 Avatar asked Nov 17 '10 22:11

helion3


People also ask

How do I exclude a directory in find?

We can exclude directories by using the help of “path“, “prune“, “o” and “print” switches with find command. The directory “bit” will be excluded from the find search!

How do you exclude a command?

Exclude Files and Directories from a List. When you need to exclude a large number of different files and directories, you can use the rsync --exclude-from flag. To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.

How do you use prune in find command?

Prune usage:$ find . -prune . The find command works like this: It starts finding files from the path provided in the command which in this case is the current directory(.). From here, it traverses through all the files in the entire tree and prints those files matching the criteria specified.


1 Answers

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

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

Caveat: requires traversing all of the unwanted directories.

like image 120
GetFree Avatar answered Sep 29 '22 19:09

GetFree