find . -type d
can be used to find all directories below some start point. But it returns the current directory (.
) too, which may be undesired. How can it be excluded?
find . -type d
can be used to find all directories below some start point. But it returns the current directory (.
) too, which may be undesired. How can it be excluded?
Well, a simple workaround as well (solution was not working for me on git bash)
find * -type d
It might not be very performant, but gets the job done, and it's what we need sometimes.
I use
find ./* <...>
when I don't mind ignoring first-level dotfiles (the*
glob doesn't match these by default in bash - see the 'dotglob' option in the shopt builtin: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html).Not only the recursion depth of
find
can be controlled by the-maxdepth
parameter, the depth can also be limited from “top” using the corresponding-mindepth
parameter. So what one actually needs is:POSIX 7 solution:
For this particular case (
.
), golfs better than themindepth
solution (24 vs 26 chars), although this is probably slightly harder to type because of the!
.To exclude other directories, this will golf less well and requires a variable for DRYness:
My decision tree between
!
and-mindepth
:!
for portability..
? Throw a coin.long_name
? Use-mindepth
.