October 16, 2015

How to use Aliases in Linux | Superuse your Terminal

17:48 Posted by Durga swaroop Perla , , , , , , No comments
Well, let’s face it, Linux is cool. Using Linux makes you look cool. But, for new users, may be not so much. Typing those long  commands can be a little intimidating and may even scare them off.
Wouldn’t it be awesome if there was a way, so that you won’t have to type long commands? Or even better, to create your own new commands by which you can do a lot of stuff?
You are in luck, because Aliases help you with that and much more.
 

What are Aliases anyway? 
Alias, as the name suggests is an alternate form of a previously existing command(s). So basically you are creating your own custom command with which you can do a lot of functions.
Enough with the definitions, let’s see an example.
Say you want to go to the Desktop folder. You would have to do something like this,

 [dsp@freblogg]$:~ cd /home/dsp/Desktop
How about instead of  typing all that, you just say desk like this and it takes you to Desktop?

 [dsp@freblogg]$:~ desk
Well,that can be done very easily. You need aliases for that.
So, for this case you create your alias like this.
 [dsp@freblogg]$:~ alias desk="cd /home/dsp/Desktop"
And, that is all you need to do.

Another use for aliases is to correct Miss-spelt commands which I often tend to do. I type mkdri many times instead of mkdir  and i get "Command not Found". For this I have created an alias as following.

 [dsp@freblogg]$:~ alias mkdri="mkdir" 
So, now anytime i type mkdri, it will be taken care of by this alias.

Another nifty feature of aliases is that, you can run multiple commands with a single alias. Usually when i 'cd' in to a folder, the first thing i do is do an 'ls' or 'ls -l'. So, i can add this to our desk alias as follows.

 [dsp@freblogg]$:~ alias desk="cd /home/dsp/Desktop; ls "
Terminal image showing use of Alias
 
And, in the image i have added an echo statement before the ls command. You can add as many as you want that way.

So, that is all there is about ALIASES that you need to know to create your own shortcuts.
But, one thing to remember is that, the aliases you have created this way will only be active till the session is closed, by which i mean until the terminal is closed.  So, an alias you have created in one terminal can't be used in another one.
To create permanent aliases you need to modify the bashrc file which will be covered in the next article.



As always, Stay curious and stay awesome!
----------------------------------------------------------------
Follow our blog posts @ Follow. So that you won't miss any interesting posts
Follow us on our Facebook  page @ Fre Blogg 
Head over to my You Tube channel for a lot of interesting tutorials @ You Tube


0 comments:

Post a Comment

Please Enter your comment here......