Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I can get all jpg images by using:

find . -name "*.jpg"  

But how can I add png files to the results as well?

share|improve this question
Related: find -name pattern that matches multiple patterns at SO – kenorb Apr 13 at 13:46

4 Answers 4

up vote 27 down vote accepted

Use the -o flag between different parameters.

find ./ -type f \( -iname \*.jpg -o -iname \*.png \) works like a charm.

share|improve this answer

You can combine criteria with -o as suggested by Shadur. Note that -o has lower precedence than juxtaposition, so you may need parentheses.

find . -name '*.jpg' -o -name '*.png'
find . -mtime -7 \( '*.jpg' -o -name '*.png' \)  # all .jpg or .png images modified in the past week

On Linux, you can use -regex to combine extensions in a terser way. The default regexp syntax is Emacs (basic regexps plus a few extensions such as \| for alternation); there's an option to switch to extended regexps.

find -regex '.*\.\(jpg\|png\)'
find -regextype posix-extended -regex '.*\.(jpg|png)'

On FreeBSD, NetBSD and OSX, you can use -regex combined with -E for extended regexps.

find -E . -regex '.*\.(jpg|png)'
share|improve this answer
finally found it! Thanks to find -E and -o I'm in business on OSX. Thanks Gilles! – Natetronn Mar 21 '13 at 3:34

This is more correct.

find -iregex '.*\.\(jpg\|gif\|png\|jpeg\)$'
share|improve this answer
Why do you say it is "more" correct? – Kevin Nov 17 '12 at 3:51
@Kevin I guess because -iregex matches jpg as well as JPG Jpg jpG and such. I think the $ isn't needed. – ott-- May 19 at 10:41
This works fine on MinGW. – Peter Mortensen Sep 18 at 11:30

To make it clear, the only optio that works on Linux, Unix and OS X flavour is:

find -E . -regex '.*\.(jpg|png)'

That's because the OS X version is a little bit different, but that's important to write things that go well on most platforms.

share|improve this answer
-E flag is not valid for find on Ubuntu 14.04 – gogaman Jul 25 '14 at 17:33
The -E flag is not valid on MinGW either (at least the version/configuration I tried it on (default configuration for a particular version)). – Peter Mortensen Sep 18 at 11:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.