Find all directories that contain a certain character and print them out
Solution 1:
The following commands perform the required query:
find -name "*c*" -type d
- starts with the current directory (no need to specify directory in case of current directory)
-
-name "*c*"
- with name contains the letterc
-
-type d
- which are a directory
You 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
Solution 2:
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.