How to use multiple filename search patterns with Linux find

Unix/Linux find FAQ: How do I use the Linux find command to find multiple filename extensions (patterns) with one command?

Problem

You want to use the Linux find command to search for multiple filename types (or patterns). You know you can run the find command several times, one for each filename extension you’re looking for, but there must be a way to search for multiple filenames at one time.

Solution

Yes, you can search for multiple filename extensions/patterns with one Unix find command. The syntax is a little obscure and hard to find, but here are several examples.

First, here’s a find command example that searches for all files beneath the current directory that end with the filename extensions .pl or .pm:

find . -type f \( -name "*.pl" -o -name "*.pm" \)

Here’s a second find command example that searches for all files beneath the current directory that end with the filename extensions .java, .xml, or .html:

find . -type f \( -name "*.java" -o -name "*.xml" -o -name "*.html" \)

Comments

Permalink

This piece of information was exactly what I was looking for. Thanks for posting it.

Permalink

Extremely useful. Thank you very much!

Permalink

Thanks for posting this. Saved me a lot of time

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.