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.<
Use the -prune
switch. For example, if you want to exclude the misc
directory just add a -path ./misc -prune -o
to your find command:
find . -path ./misc -prune -false -o -name '*.txt'
Here is an example with multiple directories:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -false -o -name '*.txt'
Here we exclude ./dir1, ./dir2 and ./dir3 in the current directory, since in find
expressions it is an action that acts on the criteria -path dir1 -o -path dir2 -o -path dir3
(if dir1 or dir2 or dir3), ANDed with type -d
.
To exclude directory name at any level, use -name
:
find . -type d \( -name node_modules -o -name dir2 -o -path name \) -prune -false -o -name '*.json'