Linux find: How to search multiple directories with find

Problem: You need to use the Unix/Linux find command to search multiple folders. Specifically, you'd like to search several folders beneath your current location, but not all folders.

For example, your current directory may have 20 subdirectories, and you don’t want to search them all like this:

find . -name "*.java"

or this:

find * -name "*.java"

Solution

To search multiple subdirectories with the find command, but not all of them, specify their names at the beginning of the find command. For instance, if you want to search two folders named foo and bar for all "*.java" files, use this command:

find foo bar -name "*.java"

And if you want to search three folders named foo, bar, and baz for all "*.rb" files, use this command:

find foo bar baz -name "*.rb"

If you want to search multiple directories with find, I hope that's helpful.

This website is a little one-man operation. If you found this information helpful, I’d appreciate it if you would share it.

Permalink

Hi...Its too good info for the beginnners..keep posting advances concepts....

Thanks
Gorak

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.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.