I can get all
jpg images by using:
find . -name "*.jpg"
But how can I add
png files to the results as well?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
-o flag between different parameters.
find ./ -type f \( -iname \*.jpg -o -iname \*.png \) works like a charm.
NOTE There must be a space between the bracket and its contents or it won't work.
-type f- only search for files (not directories)
\)- are needed for the
-type fto apply to all arguments
-o- logical OR operator
-name, but the match is case insensitive
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)'