See
BLT.
alias: Alias as a word is used in several situations in Linux, so I will come back to discuss more later.
Command Alias
One use is to change what you must type to invoke a command. For example, you could create an alias like gohome to invoke the command (at the command line) cd /home/user01.
It is my (new) intent to start including the common alias for any command on the page defining that command.
Dangers
Many Linux systems come with predefined aliases. This can be good and bad. For example, rm is commonly defined as an alias for rm -i, which makes the rm (delete) command interactive -- it asks before deleting each file. This is great, until you start working on a system where this alias is not defined.
Defeating
There are various ways to delete or temporarily defeat an alias. To temporarily defeat an alias, invoke the underlying command with the full path to the command. For example, to invoke rm "non-interactively", type /usr/bin/rm (assuming rm is in /usr/bin).
Creating
alias <alias>="<command>
unalias <alias>
An alias becomes part of your
environment. (Thus, if you set an alias in one environment, it will only be effective in that environment, and will not be effective if you leave that evironment.)
Thus, although an alias can be set in any of these locations:
- at the command line (Ok for temporary use -- they disappear (with the environment) when that command shell closes
- /etc/profile.d/ (not recommended -- not exactly sure why at this point -- I think maybe this sets the alias for all users (at the time a user is created))
- ~/.bash_profile (not recommended)
- ~/.bashrc (not recommended)
The recommended approach is to put your aliases in ~/.aliases (create the file if it doesn't exist) (see
~/..
A specific order is recommended -- put all your desired aliases first, followed by any unalias commands.
Then "source the file" in ~/.bashrc by adding the line:
source ~/.aliases
to your ~/.bashrc file.
During a shell session, you can source your ~/.bashrc file by issuing the command:
. ~/.bashrc
at the command prompt to refresh your alias definitions (like if you add a new alias to ~/.aliases during a session.
Contributors
- RandyKramer - 16 Jan 2002
- <If you edit this page, add your name here, move this to the next line>