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?
If I have this directory:
ls -l
lrwxrwxrwx 1 nagios nagios 11 août 2 18:46 conf_nagios -> /etc/icinga
-rw------- 1 nagios nagios 724930 août 15 21:00 dead.letter
-rw-r--r-- 1 nagios nagios 12312 août 23 00:13 icinga.log
-rw-r--r-- 1 nagios nagios 8323 août 23 00:12 icinga.log.gz
drwxr-xr-x 2 nagios nagios 4096 août 23 16:36 tmp
To get all directories, use -L to resolve links:
ls -lL | grep '^d'
drwxr-xr-x 5 nagios nagios 4096 août 15 21:22 conf_nagios
drwxr-xr-x 2 nagios nagios 4096 août 23 16:41 tmp
Without -L:
ls -l | grep '^d'
drwxr-xr-x 2 nagios nagios 4096 août 23 16:41 tmp
conf_nagios directory is missing.
This has been working for me:
`ls -F | grep /`
(But, I am switching to echo */ as mentioned by @nos)
Try this ls -d */ to list directories within the current directory
find . -maxdepth 1 -type d -name [^\.]\* | sed 's:^\./::'
The answer will depend on your shell.
In zsh, for example, you can do the following:
echo *(/)
And all directories within the current working directory will be displayed.
See man zshexpn for more information.
An alternative approach would be to use find(1), which should work on most Unix flavours:
find . -maxdepth 1 -type d -print
find(1) has many uses, so I'd definitely recommend man find.
Since there are dozens of ways to do it, here is another one:
tree -d -L 1 -i --noreport