I want to locate a sub-directory build/debug
within a folder
Are there any shell command that can do this?
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
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.
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"
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.