views:

375

answers:

5

Is there a simple way to recursively find all files in a directory hierarchy, that do not end in a list of extensions? E.g. all files that are not *.dll or *.exe

UNIX/GNU find, powerful as it is, doesn't seem to have an exclude mode (or I'm missing it), and I've always found it hard to use regular expressions to find things that don't match a particular expression.

I'm in a Windows environment (using the GnuWin32 port of most GNU tools), so I'm equally open for Windows-only solutions.

+2  A: 

You could do something like...

find . | grep -v '(dll|exe)$'

The -v flag on grep specifically means "find things that don't match this expression."

VoteyDisciple
grep -v '\.(dll|exe)$' would prevent matching againsta a file or dir named "dexe" for example
AlberT
+8  A: 
find . ! \( -name "*.exe" -o -name "*.dll" \)
Chen Levy
more clear and concise than others, +1
AlberT
+4  A: 
$ find . -name \*.exe -o -name \*.dll -o -print

The first two -name options have no -print option, so they skipped. Everything else is printed.

Autocracy
+4  A: 

Or without '(' and the need to escape it:

find . -not -name "*.exe" -not -name "*.dll"

and to also exclude the listing of directories

find . -not -name "*.exe" -not -name "*.dll" -not -type d

or in positive logic ;-)

find . -not -name "*.exe" -not -name "*.dll" -type f

--Hardy

Hardy
This almost looks like plain english :) Thanks for makeing me realize tehe usefulness of the logical operators of `find`
Cristi Diaconescu
+1  A: 
logic