Making Directory Listing – Make Sense !!

Normally when we give “ls -l” command or “ll” command it shows us all the files and directories in alphabetic order.

Sometimes it will be pain in the neck, if you are looking for a directory or looking for file. (as it will show you both)

There is as such no command available (to my knowledge) which will show you directories only and files only, as per your specification.

But we can do a SMALL tweak, to make our job easier.

Here is the command to view directories only :

ls -l | egrep '^d'

And, here is the command to view files only :

ls -l | egrep -v '^d'

You can also create some alias for these big command, as it is not practically good to write the same code again and again

alias llf="ls -l | egrep -v '^d'"
alias lld=ls -l | egrep '^d'"

You can always use “.bash_profile” file to make these aliases permanent.

PS: Check out – http://www.youtube.com/user/networknutsdotnet

for video of this small trick.

For more tips and trick on linux – www.networknuts.net
God Bless.

Advertisements