1

When using find what is the correct format to say "Find files that end in .jpg OR .png"?

Is it as simple as using the | operator/character?

find -iname "*.jpg|*.png" 
heemayl
  • 54,820
  • 8
  • 124
  • 141
sazr
  • 241
  • 1
  • 3
  • 8
  • 5
    Does this answer your question? [How to use find command to search for multiple extensions](https://unix.stackexchange.com/questions/15308/how-to-use-find-command-to-search-for-multiple-extensions) – Pablo A Jan 08 '20 at 18:49

1 Answers1

2

No.

You need to use -o (OR) in find like:

find \( -iname '*.jpg' -o -iname '*.png' \)

Your one would be close to correct if you are matching Regex:

find -iregex ".*\(jpg\|png\)" 

Or using extended Regex:

find -regextype posix-extended -iregex ".*(jpg|png)" 
heemayl
  • 54,820
  • 8
  • 124
  • 141
  • +1. FYI, `-regextype egrep` also gives you extended regular expressions with GNU extensions (like `\w` and `\b` and `{n,m}` intervals) and is shorter to type. see `pinfo find --node 'Regular Expressions'` – cas May 10 '16 at 01:27
  • @cas Thanks..On my GNU `find` 4.4.2 (Ubuntu 14.04) it is `posix-egrep` – heemayl May 10 '16 at 04:26
  • mine is the findutils 4.6.0+git+20160126-2 package in debian sid. (although, oddly, `find --version` says 4.7.0-git). I've been using `-regextype awk` until recently, but that doesn't support the gnu extensions. – cas May 10 '16 at 04:28