When working on the command line, you'll likely find that you're executing the same command multiple times. It's the case that frequently these commands will be invoking multiple switches and can grow quite long. You can save keystrokes by declaring user-defined aliases, each of which will correspond to a pre-set command, including switches.
Aliases can either be temporary or permanent. A temporary alias is one which will be active only as long as your current shell is active. When you log out and come back later, these aliases are no longer in effect. A permanent alias is one which will remain in effect across different sessions.
All active aliases can be displayed by issuing 'alias' at your command prompt. The following is the result of issuing the command on a freshly installed Ubuntu system.
demo@ubuntu:~$ alias
alias ls='ls --color=auto'
Linux distributions typically keep the number of pre-defined aliases to a minimum. It is up the the users to decide which commands they need to make available via aliases.
A temporary alias can be defined by issuing a single command. Here is an example which will define an alias of 'wgetpage' and assign the appropriate wget command line arguments necessary to save a local copy of a remote web resource.
demo@ubuntu:~$ alias wgetpage='wget --html-extension --recursive --convert-links --page-requisites --no-parent $1'
After issuing this command, you can inspect the results returned from 'alias' and will note that the alias has been added to the list.
demo@ubuntu:~$ alias
alias ls='ls --color=auto'
alias wgetpage='wget --html-extension --recursive --convert-links --page-requisites --no-parent $1'
The alias, wgetpage, is temporary and will not persist across different sessions. If you want an alias to be persisted across different sessions, you need to make it a permanent alias.
In a bash shell, you can find all permanent aliases by inspecting .bash_aliases in your home directory. Sometimes they can also be found in .bashrc, however this is not the proper place for them. These are called permanent aliases since they persist across multiple sessions and will remain active until manually removed.
To define a permanent alias, you can open .bash_aliases which is located in your home directory and append your own aliases to the end of that file. If you do not have a file names .bash_aliases, you can look in .bashrc and if there are already aliases defined in that file, you may wish to append your aliases there, although this is technically not the correct place for them.
Once an alias is added to one of the files indicated above, it will not become active until your next login session. If you wish to activate it immediately, you should issue the command, '. .bash_aliases'.
Removing aliases is as simple as adding them. To remove an alias from your current session, issue the 'unalias' command followed by the alias which you wish to remove as such:
demo@ubuntu:~$ alias
alias ls='ls --color=auto'
alias wgetpage='wget --html-extension --recursive --convert-links --page-requisites --no-parent $1'
demo@ubuntu:~$ unalias wgetpage
demo@ubuntu:~$ alias
alias ls='ls --color=auto'
This command sequence shows the current aliases prior to removing wgetpage from the list. After issuing 'unalias wgetpage', I've issued 'alias' again to show that it has been removed from the list of active aliases. If this alias was a temporary alias when it was created, as it was in this instance, it will not return when we start a new session on our server. If the alias was permanent and defined in one of the files mentioned above, then it will return. In order to remove this alias permanently, we need to either comment out the line in .bash_aliases with a # or simply delete the line altogether.