Linux or UNIX-like system use the ls command to list files and directories. However, ls does not have an option to list only directories. You can use combination of ls command, find command, and grep command to list directory names only. You can use the find command too.
Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.
ls is a Linux and Unix command that allows you to list all files and directories in a directory. You can also use ls -d to view only directories and use ls -f to view only files as shown above.
Try this ls -d */
to list directories within the current directory
Try this:
find . -maxdepth 1 -type d
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
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 *(/)
Since there are dozens of ways to do it, here is another one:
tree -d -L 1 -i --noreport
ls -l | grep '^d'
You can make an alias and put it into the profile file
alias ld="ls -l| grep '^d'"
find . -maxdepth 1 -type d -name [^\.]\* | sed 's:^\./::'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With