You can provide your own name for commands using the alias command. An alias allows a user to create simple names or abbreviations (even consisting of just a single character) for commands, regardless of how complex the original commands are, and then use them in the same way that ordinary commands are used.
In its simplest form, you just set the command name you want to use equal to the original command, which you surround with single quotes. For example, if a user wants to exit with a personal command such as cu (i.e., “see you”):
To make an alias permanent, you need to add it to the hidden file in your Home directory .bashrc or create a separate file called .bash_aliases.
- Open that file in Leafpad or another text editor
- Find a convenient spot near the bottom to enter your alias command following the model in the example above
- It is a good idea to precede your new alias with a commented explanation: #
- Note that if you are going to use the alias when root, you will need to copy (or recreate) that document in the /root directory.
Here is a useful example of an alias that saves a lot of keystrokes for a common command:
alias up=’su -c “apt-get update && apt-get upgrade”‘
(Note the use of double quotes inside single quotes.) This gives you a very fast input method of updating and upgrading your installed packages.
Remove an alias
You can remove an alias for a single terminal session or permanently.
- Single-session removal: use unalias. From the first example above, typing
- unalias cu
- would remove that alias for one terminal session.
- Permanent removal: delete the corresponding line in ~/.bashrc.