Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that?

EDIT: I'm using Mac OS X, and ls -d gives me . even though I have directories.

share|improve this question
Can somebody explain why ls -d gives only . and why the */ must be added to the end to make it work? –  cwd Oct 4 '11 at 2:49
@cwd If you don't specify any files, ls defaults to .. And -d means don't print the directory's contents, print the directory itself. –  Mikel May 23 '12 at 14:52
@cwd try using ls -p it shows the / after the directory names. So */ is just a pattern which is matched against the directory name and / combo. –  Pitt Oct 24 '12 at 15:55

5 Answers 5

up vote 33 down vote accepted

I know there is already a selected answer, but you can get the requested behavior with just ls:

ls -ld -- */

This will list all the directories in the current working directory where it is run. To get all the subdirectories of some other folder, just try:

ls -ld /path/to/directory/*/

Note that the -l is optional.

share|improve this answer
Nice. I never considered that directories have an implicit / on the end--but now that I see you answer it makes sense. After all, tab-completion always adds it. –  gvkv Sep 6 '10 at 3:46

I also needed to view hidden directories so have modified the suggestion above to fit my needs

ls -ad */ \.*
share|improve this answer

I like the tree utility to get an overview over the directory structure. It's available in MacPorts and all Linux distributions I've tried.

tree -d -L 2

That would show all directories, two levels deep.

share|improve this answer

I think ls has a bug on Mac OS X. A workaround is to use grep... ls -l / | grep "^d"

share|improve this answer
It's nice to know I'm not the only person that uses the grep "^d" hack –  Michael Mrozek Sep 6 '10 at 2:10
As far as I know, the behavior he describes is not a bug and is the same if one is using GNU ls. The -d option displays the listing for the directory and not the contents. To see why this can be useful see the difference between: ls -l /home and ls -dl /home –  Steven D Sep 6 '10 at 2:11

No, but a simple find command will do it:

find . -type d -depth 1

or grep

ls -F | grep /

You could then alias either one if necessary.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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