Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all files with a particular parent directory in linux?

Tags:

linux

How do you find all files with a particular parent directory in the linux command terminal?

I know to find all files using find like so:

find . -name filename.extension

But is it possible to find all filename.extension files with the parent directory of foldername?

I have tried the following but this does not work:

find . -name foldername/filename.extension

And I cannot find any example of how to do this.

So some example results I would expect are as so:

./example/project/website/foldername/filename.extension
./folder/demo/foldername/filename.extension
./more/files/foldername/filename.extension
./business/assets/foldername/filename.extension
./steven/foldername/filename.extension

Is there anyway to do this?

like image 812
3dgoo Avatar asked Jan 07 '13 05:01

3dgoo


People also ask

How do you find a list of files from some specific folder Linux?

Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.

How do I search an entire file system in Linux?

You need use the find command. It search for files in a directory hierarchy under Linux and all other UNIX like operating systems. Use find command to find a file from shell prompt when using the Terminal or ssh based session.


2 Answers

Use -path switch with find

find . -path \*/foldername/filename.extension
like image 131
Vikas Avatar answered Sep 19 '22 13:09

Vikas


Just try this

locate "/*/foldername/filename.extension"

provided you have updated index with updatedb

like image 31
Mirage Avatar answered Sep 17 '22 13:09

Mirage