How to use multiple filename search patterns with Linux find

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 Unix/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" \)
Permalink

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

Permalink

Extremely useful. Thank you very much!

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.