Listing only directories using ls in Bash?

Sibi picture Sibi · Jan 16, 2013 · Viewed 879.4k times · Source

This command lists directories in the current path: ls -d */

What exactly does the pattern */ do?

And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents) for listing only directories in that path?

Answer

Gordon Davisson picture Gordon Davisson · Jan 16, 2013

*/ is a pattern that matches all of the subdirectories in the current directory (* would match all files and subdirectories; the / restricts it to directories). Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/