Listing only directories in UNIX
I want to list only the directories in specified path (
ls doesn't have such option).
Also, can this be done with a single line command?
ls -d */ to list directories within the current directory
Read more... Read less...
find . -maxdepth 1 -type d
find * -maxdepth 0 -type d
basically filters the expansion of '*', i.e. all entries in the current dir, by the
-type d condition.
Advantage is that, output is same as
ls -1 *, but only with directories
and entries do not start with a dot
You can use
ls -d */ or
Another solution would be globbing but this depends on the shell you are using and if globbing for directories is supported.
For example ZSH:
zsh # ls *(/)
Since there are dozens of ways to do it, here is another one:
tree -d -L 1 -i --noreport
- -d: directories
- -L: depth of the tree (hence 1, our working directory)
- -i: no indentation, print names only
- --noreport: do not report information at the end of the tree listing
ls -l | grep '^d'
You can make an alias and put it into the profile file
alias ld="ls -l| grep '^d'"