Linux find folder inside subfolders

19

4

I am trying to find a directory named 480debugerror nested under child directories. I don't know the exact path, or even if I have the exact spelling of the directory I want to find.

Is there a Linux command to find directories with a given prefix or suffix, for example directories with a name of "debug" or "debug error", with some prefix or suffix that is unknown?

Bharanikumar

Posted 2011-01-21T13:29:01.220

Reputation: 319

2You can try locate (locates files) or find (finds files). – miku – 2011-01-21T13:31:29.533

find -type f -name *ummy... but not get – None – 2011-01-21T13:32:54.543

3You need -type d. f searches for files – thkala – 2011-01-21T13:34:10.750

Answers

16

find is what you need:

$ find -type d -name '*debugerror*'

or

$ find -type d -name '480debugerror'

if you are certain about the folder name.

thkala

Posted 2011-01-21T13:29:01.220

Reputation: 1 769

8

find . -type d \( -iname '*error*' -o -iname '*debug*' \) 

Zsolt Botykai

Posted 2011-01-21T13:29:01.220

Reputation: 627

1

In bash,

shopt -s nullglob globstar
echo **/*480*/
echo **/*debug*/
echo **/*error*/

searches recursively for directories with names containing 480, debug or error.

user2394284

Posted 2011-01-21T13:29:01.220

Reputation: 871

1

locate -i "480debugerror"

will check a database that lists all the files indexed on your PC. I often have scenarios like this and so I do searches like:

locate -i "debug" | grep -i "log"

which finds all files that have in their path (regardless of case [that's what -i means]) "debug" and "log" (In case you don't know, the | grep means search within the results that locate produces)

The advantage to using locate over find is that locate will produce output much faster (since it's only checking a database) but if the file/folder is not indexed then it will not find anything. (to update the database you can use sudo updatedb)

jcuenod

Posted 2011-01-21T13:29:01.220

Reputation: 179

Only if you have slocate installed. Some production environment does not :-( – Zsolt Botykai – 2011-01-21T14:28:48.450

True but if an option I would say it's superior to find... – None – 2011-01-21T14:47:47.143