i want to list only the directories in specified path(ls don't have such option). Also, can this be done with a single line command?
Try this ls -d */
to list directories within the current directory
find specifiedpath -type d
If you don't want to recurse in subdirectories, you can do this instead:
find specifiedpath -type d -mindepth 1 -maxdepth 1
Note that "dot" directories (whose name start with .
) will be listed too; but not the special directories .
nor ..
. If you don't want "dot" directories, you can just grep
them out:
find specifiedpath -type d -mindepth 1 -maxdepth 1 | grep -v '^\.'
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
.
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 *(/)