Thursday, 22 August 2013

Bash Tricks. Ailases.


Are you using a Linux machine ? Are you lazy to type in the commands like "sudo apt-get install #package-name" to install software ?? If yes, then read on.

The basic idea is to create a small hack that you can use to get rid of the nasty "sudo apt-get install" (for Debian based operating systems). But that being said this tutorial can be used by other 'non-debian' distro's as well !!


There may  be other ways of achieving the same result but the one that I'm using here is through "bash". (You can visit the link to get a good understanding of what bash is and what it is capable of doing).
 
Why bash ?
  • A it comes pre-installed with all Linux-Unix based Operating systems.
  • It's really simple to alter the way that you use some of the standard Linux commands.(As you will see shortly).

 What tools do I need to install to follow the tutorial ?
  •  Well if you have a Linux distro that would be all that you would need.

  Ok I have a Linux distro what next ?
  • Great !!! without further ado lets get hacking :)

Steps involved:-

  1. Open your file manager. And go to your home folder.(Usually it has the same name as that of the currently logged in user).
  2. Show hidden files by pressing "ctrl+h". And look for ".bashrc" file.(If you don't have it just create one.)
  3. Open the .bashrc file in your favorite text editor.
  4. Scroll down to the section which say "aliases. (If you created the file by your self then just add the following lines).
  5. Add an alias that you want. In this case we want to make the "sudo apt-get install" shorter, hmmm lets replace all that only by "install". 
  6. Add the following. [alias install  = "sudo apt-get install"]. Note do not include the braces.
  7. Save the file and exit out of it.
  8. Next we would want to load this setting by default when ever you login or do a fresh boot.
  9. Going back to your home folder. Create a file and call it ".bash_profile" (Note do not include the inverted commas).
  10. Open the ".bash_profile" and paste in the following code. "[ -f $HOME/.bashrc ] && . $HOME/.bashrc". (Note do not include the inverted commas).
  11. Save this file and exit out.
  12. Open terminal make sure your are in the home path. And source the .bash_profile that you just created by typing the following command in the terminal.
  13. "source ~/.bash_profile". (Note do not include the inverted commas").
  14. Add viola your done. Logout and log back in and install new software by typing "install #package_name".