1

I want to locate a sub-directory build/debug within a folder

Are there any shell command that can do this?

4 Answers 4

6

This should do it.

find . -type d -path '*/build/debug'

Test harness:

$ mkdir -p tester/{1..3}/build/debug
$ find tester -type d -path '*/build/debug'
tester/1/build/debug
tester/2/build/debug
tester/3/build/debug
3

If you turn on globstar (with shopt -s globstar), you can use double-asterisk for recursive wildcards in bash.

$ mkdir -p tester/{1..3}/build/debug
$ mkdir -p tester/anotherlevel/{1..3}/build/debug
$ mkdir -p tester/anotherlevel/yetanother/{1..3}/build/debug
$ shopt -s globstar
$ file tester/**/build/debug
tester/1/build/debug:                         directory
tester/2/build/debug:                         directory
tester/3/build/debug:                         directory
tester/anotherlevel/1/build/debug:            directory
tester/anotherlevel/2/build/debug:            directory
tester/anotherlevel/3/build/debug:            directory
tester/anotherlevel/yetanother/1/build/debug: directory
tester/anotherlevel/yetanother/2/build/debug: directory
tester/anotherlevel/yetanother/3/build/debug: directory

I'm using file here just to show what we're talking about but you can use this for all sorts of things.

0
1

The grep way

find /your/sub/dir -type d -print0 

prints all your files to the console. Now only output the ones you want to see by using grep

find /home/tim/Apps -type d -print0 | grep -FzZ "debug/build"
-1

Execute the command

find -name 'foldername'

This will find all folders (and files) of that name and show the path to it. The search start from the current folder you are in downwards. So if you have no idea where it is then cd / first so that you are in the root top folder. You might also want to add sudo in front of the command to make sure the search checks folder you do not have permissions too.

1
  • 1
    This won't do because build/debug is not a unix filename. This call will return a warning, because "build/debug" will always be false for this particular foldername. "Use 'find ... -print0 | grep -FzZ "debug/build"' instead" the console says if this command is issued...
    – mondjunge
    Sep 20, 2013 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .