linux - [Solved-5 Solutions] Exclude directory from find . command - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
To run a find command for all JavaScript files, but how to exclude a specific directory ?
Here is the Code:
Linux - Solution 1:
Use the prune switch, for example if you need to exclude the misc directory just add a -path ./misc -prune -o to your find command:
Here is an example with multiple directories:
Here we exclude dir1, dir2 and dir3, 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. Further action is -o print, just print.
Linux - Solution 2:
Linux - Solution 3:
One option would be to exclude all results that contain the directory name with grep. For example:
Linux - Solution 4:
I used this to find all files not in ".*" paths:
Linux - Solution 5:
It will search for MP3 files in the current folder and subfolders except in dir1 subfolder.
Use:
To exclude dir1 AND dir2