using bash find command to list *.h and *.cpp
I can do this to get all the .h files in the current dir and subdirs:
find . -name *.h and can get all the .cpp files as a minor variation. But how do I get .h *and* .cpp files with a single "find" call? First I figured out that I need to do this: shopt -s extglob to turn on fancier pattern matching. That allows operators like this: +(pattern-list) Matches one or more occurrences of the given patterns I am able to use this technique with "ls": ls *+(h|cpp) to get *.h and *.cpp. But how to do this with "find"? This: find . -name '*+(cpp|h)' doesn't work. -Walter Gillett |
Try this
Code:
find /some/directory -type f \( -name '*.h' -o -name '*.cpp' \) -exec ls {} \; |
As a further note, find is NOT a bash builtin, and will so be unable to make use of those extended shell options. /bin/ls would be equally unable to do so, but the bash builtin ls can use it. :) Tiny little tricks that will catch you.
|
Re: using bash find command to list *.h and *.cpp
Thanks for the example, works great, thanks also for the info on shell options!
-Walter |
All times are GMT -5. The time now is 04:21 AM. |