I would like to list only directories (including hidden) in a given directory (for example /etc/) if I'm not in this directory.

If I want to list all directories, including hidden I use the command:

ls -d */ .*/

I wanted to use this command to list all directories in /etc.

ls /etc

I can do this, but I wanted to combine it with the first one, listing only directories.

ls -d */ .*/ /etc


ls /etc -d */ .*/

don't work. Why?

2 Answers 2


It doesn't work because */ and .*/ are not arguments that are passed directly to ls - instead, they are globs that are expanded by the shell, giving a list of matching filenames in the current directory that are themselves passed to ls

The equivalent for a different directory (/etc say) would be

ls -d /etc/*/ /etc/.*/

If your shell supports brace expansion, you can write that more compactly as

ls -d /etc/{,.}*/
find /etc/ -maxdepth 1 -type d

Use above command to list only directories including hidden directory being in some other directory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .