27 January 2012

Save Time with Aliases

Leave a Comment
alias command in Linux/Unix

                                           alias is nothing but a different name or shortcut of the original command in Linux/Unix.The purpose of aliases in Linux/Unix is that you can name a command in your own way , this helps to remember a command in a much easier way. If aliases used properly then this can cut down on typing.


alias  newcommand='original_command '

1. alias : keyword
2. newcommand : user-define name
3. original_command : Actual command

$ sandeep
sandeep: command not found

$ ls
abc.lst    def.lst    examples.desktop    js

$ alias sandeep=ls

$ sandeep
abc.lst    def.lst    examples.desktop   js

*In above example we have created alias for ls command.
* These type of aliases are temporary i,e they are active only for current session ,once you Logout from your shell these aliases will destroy and you will not able to use them.

So how , you make your aliases permanent ??  To make your aliases permanent you have to edit your ~/.bashrc file or ~/.profile(which ever exist in your system) . Mention all the aliases in the end of  ~/.bashrc file or ~/.profile ,  that you want to use each time you Login in your account.

How can I edit my ~/.bashrc file

1. Go to your home directory  if you are not in your home directory , simply type


2. Open .bashrc file with any editor and move to the end of the file

         vim .bashrc

* There may be some aliases already exist in .bashrc file ,  but they are commented(#)  uncomment(remove #) them  to make them effective if you want.

3. Mention your aliases and save it.

Hurry you have made your aliases permanent , now you will be able to use it each time you Login in your account.

How to remove aliases??

1. If aliases are temporary you can remove it by using unalias command


unalias alias_name

$ sandeep
sandeep: command not found

$ alias sandeep=ls

$ sandeep
abc.lst     def.lst     examples.desktop    js

$ unalias sandeep

$ sandeep
sandeep: command not found

2. If aliases are permanent then delete those aliases from ~/.bashrc or ~/.profile file to remove it.

Some Important aliases you should which make your command line experience much easier

1. alias list_all='ls -a'
ls -a list all files in your current directory (hidden also).

2. alias long_list='ls -l'
ls -l is use for long listing of file.

3. alias rm='rm -i' 
*This one is most important , you should make it permanent . This saves you from accidental removal of any file or directory.

$ alias rm='rm -i'
$ rm abc.lst
rm: remove regular file `abc.lst'? n

4. alias cp='cp -i'
*Interactive copying

alias command can be used to see list of all the  aliases on your system

$ alias
alias cp='cp -i'
alias ls='ls --color=auto'
alias rm='rm -i'

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...


Post a Comment