Is there a built-in command or a less verbose way of achieving this?
find /var/foo -maxdepth 1 -mindepth 1 -type d
Or should I just make a tiny shell script or function if I'm doing this sort of thing often?
Is there a built-in command or a less verbose way of achieving this?
find /var/foo -maxdepth 1 -mindepth 1 -type d
Or should I just make a tiny shell script or function if I'm doing this sort of thing often?
"-d" means don't delve into the directories, the "*/" only matches directories.
The shortest command seems to be
I believe that will non-recursively list all the subdirectories of
/var/foo
, no matter how stupidly named the directories are or if non-ASCII characters are involved.However,
find /var/foo -maxdepth 1 -mindepth 1 -type d
is easier to both remember and type.Below is my original self-answer.
If one cares not about files beginning with a dot then mibus' answer of
would be short and effective. However if one would like the hidden files to be included then one needs to either stick with
or try
The -F places / and the end of directory names (as well as other characters for other types of files). The -A causes files starting with a dot to be included, except for '.' and '..'. That is why -a is not used. The grep won't get any false positives since '/' is not allowed in filenames (at least for POSIX filesystems).
Regarding performance, on my Ubuntu Jaunty installation with just shy of 32k files and directories in /var/foo, find is the fastest, followed by ls -d, and ls -FA with grep comes in last.