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?
Long listing of directories
Listing directories
- ls -d */
Try this:
find . -maxdepth 1 -type d
You can use ls -d */
or tree -d
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 *(/)
### If you need full path of dir and list selective dir with "name" of dir(or dir_prefix*):
find $(pwd) -maxdepth 1 -type d -name "SL*"
Here's another solution that shows linked directories. I slightly prefer it because it's a subset of the "normal" ls -l output:
ls -1d */ | rev | cut -c2- | rev | xargs ls -ld --color=always
The following
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