上QQ阅读APP看书,第一时间看更新
How to do it...
These are the operations you can perform on aliases:
- Create an alias:
$ alias new_command='command sequence'
This example creates a shortcut for the apt-get install command:
$ alias install='sudo apt-get install'
Once the alias is defined, we can type install instead of sudo apt-get install.
- The alias command is temporary: aliases exist until we close the current terminal. To make an alias available to all shells, add this statement to the ~/.bashrc file. Commands in ~/.bashrc are always executed when a new interactive shell process is spawned:
$ echo 'alias cmd="command seq"' >> ~/.bashrc
- To remove an alias, remove its entry from ~/.bashrc (if any) or use the unalias command. Alternatively, alias example= should unset the alias named example.
- This example creates an alias for rm that will delete the original and keep a copy in a backup directory:
alias rm='cp $@ ~/backup && rm $@'
When you create an alias, if the item being aliased already exists, it will be replaced by this newly aliased command for that user.