I’m using
DIRS=$(find . -type d)
to get get all directories recursively. Now I need to look at that list and print only the paths that have more than n number of directories. So I need to search for the ‘/’ character in the path, but the methods I’m using to search for it aren’t working.
Would this also work for you?
The command
find .simply lists all files and directories in the current directory, recursively. Using-type d, we restrict it to list directories only. Using-mindepth $n, we require that each directory it at depth at least$n(set e.g.n=2, or just substitute the number directly instead of$n). Seeman findfor more information.The
$(...)construct runs the given command and is substituted by its output; it is roughly equivalent to`...`. Finally, this output is assigned to theDIRSvariable.