find files within a specific directory structure but a variable parent directory structure

7

2

I want to use the find command in linux to find a specific file nested within a specific directory structure, say dir1/dir2/reqdfile.

But this directory structure can itself be nested within any parent directory structure.

Is it possible to a search like?

find directory_to_search -name "**/dir1/dir2/reqdfile"

What is the exact syntax?

Rohit Banga

Posted 2011-01-27T10:32:23.663

Reputation: 1 814

Answers

15

Use -path instead of -name:

find directory_to_search -path "*/dir1/dir2/reqdfile"

Note that there's only one asterisk.

Paused until further notice.

Posted 2011-01-27T10:32:23.663

Reputation: 86 075

0

In general, a quick and dirty alternative would be to use grep. Though it's not as clean for find specifically, thanks to the -path option, many similar cases can be solved like so:

find directory | grep "/dir1/dir2/reqdfile$"

Jeremy Sturdivant

Posted 2011-01-27T10:32:23.663

Reputation: 2 108