Is there any way to list just the folders in a directory using bash commands? ( as the ls command lists all the files and folders )

link|improve this question

57% accept rate
feedback

3 Answers

up vote 6 down vote accepted

You can use:

ls -d -- */

Since all directories end in /, this lists only the directories in the current path. The -d option ensures that only the directory names are printed, not their contents.

link|improve this answer
feedback

Stephen Martin's response gave a warning, and listed the current folder as well, so I'd suggest

find . -mindepth 1 -maxdepth 1 -type d

(This is on Linux; I could not find -maxdepth and -mindepth in the POSIX man page for find)

link|improve this answer
Thanks for that had them wrong way round sorted now +1 – Stephen Martin Sep 14 '11 at 9:19
feedback
find . -maxdepth 1 -type d

Will list just folders. And as Teddy pointed out you'll need -maxdepth to stop it recusrsing into sub dirs

link|improve this answer
3  
You probably want -maxdepth 1 too. – Teddy Sep 14 '11 at 8:40
+1 correcto mundo – Stephen Martin Sep 14 '11 at 8:54
feedback

Your Answer

 
or
required, but never shown

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