How to display directories alone in linux ls command

Posted: January 17, 2012 in Linux
Tags: , , , , ,

Sometimes we need to display only the directories in a folder. At this case use the following command

$ ls -l | egrep ‘^d’

It will display only the directory list with some options..

If you need to see only the files, use -v to get the converse effect of the above command

$ ls -l | egrep -v ‘^d’

Every time we cant execute these big commands. Better we can use alias for these commands.

let me call ldir as list directories lf as list files..

Now, we can create alias as

$ alias ldir=”ls -l | egrep ‘^d'”

and for files

$ alias lf=”ls -l | egrep -v ‘^d'”

Now open the bash profile in vi editore

$ vi .bash_profile

Append the above two alias commands save and close.

Now, check by typing

$ ldir /etc

and

$ lf /etc

Advertisements
Comments
  1. Marc says:

    Thank you. It worked great.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s