
To match both hidden and non-hidden directories, use ls -d - */. */ to match only hidden directories without regular files). If you want them to be matched by a glob, use ls -d. * deliberately doesn't match hidden files or directories, because most of the time that's exactly what is wanted (as dot files and directories are generally used for configuration, not data), and you can override the default by explicitly specifying a glob starting with. Or *(D-/) if you do want the symlinks to directories.

If using zsh, you can do ls -d - *(D/) to list directories only (including hidden ones with D), and without adding a trailing / to each file. Also note that */ includes directories and symlinks to directories. are not included in that case which makes it behave more like ls -A).Īlso note the - that you forgot to mark the end of options to make sure file names are not treated as options if they start with. In some shells, you can ask for * to match hidden files too for example in Bash, with shopt -s dotglob (note that. To see hidden directories, you can list them explicitly: ls -d - */. , so */ doesn’t include hidden files: in combination with -d, the -a has no effect here.


* at the start of a filename pattern doesn’t match. When you run ls -d */ and ls -ad */, the shell expands */, and provides the list of filenames which ls will show. Since -a is specified, that includes showing “hidden” files. When you run ls -a, there are no filenames on the ls command line (as seen by ls), so it determines the filenames it should list by itself.
