Alias
This page was last updated on July 18, 2009.
Create a temporary alias
You can create a temporary alias that is valid only for the current session and will be forgotten by the system when you close the terminal window. To do this:
- Open a terminal window.
- Check if the name is already being used by the system by typing this command, replacing name with the name you’d like to give the alias:
- If the name is already being used, pick another name and repeat Step 2 with the new name. If it’s not being used, go to the next step.
- Type this command, replacing name with the name you’d like to give the alias and replacing command with the command you’d like the alias to perform:
- For example,:
which name
alias name='command'
alias details='ls -l'
Now I can type details instead of ls -l to see a detailed listing of files in a directory.
Create a personal alias list
To create your own alias list:
- Open a text editor and type the command for each alias on a separate line.
- Example:
- Save the file as myaliaslist wherever you’d like to keep it. For the sake of this example, let’s say you saved it to the /home/username/ directory.
- Open the .bashrc file in your /home/username/ directory with a text editor. Note that hidden files must be turned on in your file manager for this file to be visible.
- Type this line at the bottom of the file to source your alias list:
- Save the file.
- Close the text editor.
alias1='command1' alias2='command2' alias3='command3' alias4='command4'
source /home/username/myaliaslist
Now any time you open a terminal window, the aliases you have defined will be available for you to use.
Check which aliases you have defined
Type this command in a terminal window to check if you have any aliases defined in your .bashrc file:
alias
Obligatory Happy Ending
And they all lived happily ever after. The end.
