I have seen many people asking how to create an alias for terminal commands.This is a small how to: to show you how to create an alias.Ofcourse creating an alias for frequently using commands will be very helpful.
How to create an alias?
We often use update and upgrade command in our system.So let me show you how to create an alias for those commands.
So for creating an alias for update and upgrade we should type the following in terminal,
alias update='sudo apt-get update'
Now if you want to update,you can simply type update in terminal.And it will perform the action of sudo apt-get update for upgrading simply type upgrade.If you want to create an alias for both the commands then you should add an alias like this,
alias upgrade='sudo apt-get upgrade'
Like this you can create an alias for any commands you wish.These custom commands will work until you close your terminal.So to add this permanently,you should add the commands to ~/.bashrc or ~/.bash_aliases.
alias updg='sudo apt-get update && sudo apt-get upgrade'
How to add these commands to ~/.bashrc or ~/.bash_aliases file?
Edit the ~/.bashrc file,and add the commands at the end file,
After adding the commands you should run the following command in terminal to refresh your bashrc configuration.
Now you have added the alias permanently..Hope this helps someone..
If you just want to add one or two aliases, use .bashrc. If you want to add more then i recommend you to use .bash_aliases.It will prevent you from messing up the files.It's always a good idea to add your custom commands in .bash_aliases.Good Luck..!