How to display directories alone in linux ls commandirectories

How to display directories alone in linux ls command

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
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply