
How do I find files having either of several extensions? Eg this finds all .c and .h files $find . -name '*.[ch]' but what if I want to find all .cpp and .h files? I guess I need a grouping operator in the pattern but I can't figure out what it is. I've looked in the man page and Google and tried a few things, also tried the -regex switch instead of -name but couldn't get it to work. Eg this doesn't find anything $find . -regex '.*\.(cpp|h)' I suspect the answer is really simple. Any ideas what I'm doing wrong? g -- Glenn Ramsey <glenn(a)componic.co.nz> 07 8627077 http://www.componic.co.nz

On Tue, Apr 20, 2004 at 09:05:28PM +1200, Glenn Ramsey wrote:
How do I find files having either of several extensions?
Eg this finds all .c and .h files
$find . -name '*.[ch]'
but what if I want to find all .cpp and .h files?
I guess I need a grouping operator in the pattern but I can't figure out what it is.
Use "-o" for "or": find . -name \*.cpp -o -name \*.h :) John

* Glenn Ramsey <glenn(a)componic.co.nz> [2004-04-20 11:07]:
Eg this doesn't find anything
$find . -regex '.*\.(cpp|h)'
Because find(1) uses basic regexes -- you have to escape almost all metacharacters. find . -regex '.*\.\(cpp\|h\)' -- Regards, Aristotle "If you can't laugh at yourself, you don't take life seriously enough."
participants (3)
-
A. Pagaltzis
-
Glenn Ramsey
-
John R. McPherson