Display a List Of Just Subdirectories

Display a List Of Just Subdirectories
Facebook may have decided that you shouldn’t see the news, but we think you deserve to be in the know with Lifehacker Australia’s content. To sign up for our daily newsletter covering the latest news, hacks and reviews, head HERE. For a running feed of all our stories, follow us on Twitter HERE. Or you can bookmark the Lifehacker Australia homepage to visit whenever you need a fix.


Linux, Mac, or Windows with Cygwin: If you have ever wanted to show a list of subdirectories underneath the current directory while at the terminal prompt, there’s a simple command that can help. Simply run the following command from the bash terminal prompt, which filters the file listing to only show folders:

ls -l | grep ^d

Since typing that whole command every time you want to show a list of directories might get a little tiring, you can use the alias feature to assign it to something you can more easily remember:

alias lsd="ls -l | grep ^d"

Now when you type “lsd” at the prompt, you will see a list containing only the directories, which can be very useful when you are trying to navigate through a messy set of folders. For more on using the command prompt, check out our top 10 command line tools, get your own drop-down Yakuake terminal, or learn to use cron from the command line.

Comments

Log in to comment on this story!