Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix find: multiple file types

Tags:

find

unix

I want to run find -name with multiple file types. Eg.

 find -name *.h,*.cpp 

Is this possible?

like image 629
Jacko Avatar asked Aug 25 '11 12:08

Jacko


People also ask

How do I find the filename pattern in Unix?

The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.

How do I view all PNG files?

Click My PC on the left-pane in File Explorer, or Computer in Windows Explorer. Enter the command kind:=picture into the search box to search all partitions on your hard drive for images saved in JPEG, PNG, GIF and BMP formats.


1 Answers

$ find . -name '*.h' -o -name '*.cpp' 

To find this information in the man page, type man find and the search for operators by typing /OPERATORS and hit enter.

The . isn't strictly necessary with GNU find, but is necessary in Unix. The quotes are important in either case, and leaving them out will cause errors if files of those types appear in the current directory.

On some systems (such as Cygwin), parentheses are necessary to make the set of extensions inclusive:

$ find . \( -name '*.h' -o -name '*.cpp' \) 
like image 160
Eric Wilson Avatar answered Oct 13 '22 02:10

Eric Wilson