use regular expression to find files
paul
posted @ Thu, 04 Jun 2009 20:28:23 +0800
in coding life
, 1369 readers
Say you want to list all the *.py, *.cc and *.h files.
You may use the command below.
find ./ -name '*.cc' -o -name '*.h' -o -name '*.py'
But there is always a better way! So, give a try to the option -regex.
find . -regex '.*\.\(cc\|h\|py\)'
What's the backslashes in expression used for? Well, the find command uses emacs regular expression syntax!
This work is licensed under a Creative Commons Attribution 3.0 Unported License.