List only directories using ls and grep

Published On: 2012-10-22

Category: News

Normally if you try to view directories in ls, ls will look inside that directory instead of the directory itself.  For example:

You want to find out about the directories in images but images has a ton of files in it.

Running this in the images directory will get you the directory information.

ls -l | grep "^d"

We are simply looking for the first character in our ls to be a 'd'.  If so it marks a directory.