0

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

or

ls /etc -d */ .*/

don't work. Why?

1

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/{,.}*/
1
find /etc/ -maxdepth 1 -type d

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.