Linux Find Command – How to Find Certain Subdirectories

bashfindlinuxshell

Let's say I have a directory dir with three subdirectories dir1 .. dir3. And inside I have many files and other subdirectories.

I'd like to search for a file inside, say with a *.c ending, but I'd only like to search in subdirectory "dir/dir2" and all its subdirectories. How can I formulate that?

Assuming I'm in dir/ I have:

find . -name "*.c"

to search in all directories.

How do I restrict to only dir2?

Best Answer

Find will accept any valid path so

find ./dir2 -name '*.c'

should do the trick

If the dir directory is /home/user/dir you could give find the full path

find /home/user/dir/dir2 -name '*.c'
Related Question