I need to find all directories which contain a certain character in their name and print them out.
So if i have the directories:
abc cde fgh
And I search for "c" I should get:
abc
cde
I need to find all directories which contain a certain character in their name and print them out.
So if i have the directories:
abc cde fgh
And I search for "c" I should get:
abc
cde
The following commands perform the required query:
find -name "*c*" -type d
-name "*c*" - with name contains the letter c-type d - which are a directoryYou can run the command on other directory (/full/path/to/dir) using:
find /full/path/to/dir -name "*c*" -type d
More info nixCraft find command
If globstar is enabled you can use this
for d in **/*c*/; do echo $d; done
The first ** will match any arbitrary subdirectory paths. Then *c*/ with match folders with the c character in it
If it's not enabled you can enable it with shopt -s globstar
globstar
- If set, the pattern
**used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a/, only directories and subdirectories match.