Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 '15 at 13:46
up vote 38 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 '15 at 10:41
This works fine on MinGW. – Peter Mortensen Sep 18 '15 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 '15 at 11:29

Use it.

share|improve this answer
You may need to explain this a bit. – chaos Jan 15 at 7:33
God I hope you never end up writing Ikea instructions: "Step 1: Use it. Step 2: Do one." – Matt Fletcher Jul 8 at 10:40

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.