Find command not excluding folder from results

Go To StackoverFlow.com

2

I have a shell script which outputs all of the .js and .html files found in a folder provided by the user. I need to exclude a sub-folder and all its files from the search results. I'm using the find command to do this. The command I have currently excludes all the files under this sub-folder but outputs the sub-folder in results. I want to exclude a folder called "CrashLog" and all its files. The path to this sub-folder is "Users/test/Desktop/Units/JSunit/CrashLog/"

Here is the find command I'm using:

find "Users/test/Desktop/Units" -name CrashLog -prune -o -name "*.html" -o -name "*.js" 

The output includes "Users/test/Desktop/Units/JSunit/CrashLog/". How can I exclude this? I know I can use grep, but would prefer if there is solution using find itself. I'm running on Mac OSX.

2012-04-05 01:33
by smokinguns


2

You need -print, at the end and parenthesis around the file extension tests:

find "Users/test/Desktop/Units" -name CrashLog -prune -o \( -name "*.html" -o -name "*.js" \) -print
2012-04-05 02:33
by alexisdm


1

find "Users/test/Desktop/Units" -name CrashLog -prune -a \( -name "*.html" -o -name "*.js" \)
2012-04-05 01:35
by DigitalRoss
@ DigitalRoss : This doesn't give any output on my Mac - smokinguns 2012-04-05 02:27
In some circumstances, -print is implied. I tend to always supply it ... I guess I wasn't being completely retro about that after all .. - DigitalRoss 2012-04-05 04:26
using "-a" doesn't give any output. Using -o gives an outpu - smokinguns 2012-04-05 05:36
Ads