Instructions on how to add an alias for a complicated command
Last updated 2018-06-28 by Adam Lu
-
Open a terminal
-
Type one of the following commands to edit the file
~/.bash_aliases:# Use the vim editor (alias for vi ~/.bash_aliases) vi_alias # Use the nano editor (alias for nano ~/.bash_aliases) nano_alias -
Create the alias by adding a line that looks like this:
alias <alias name>='complicated command'For example,
alias store_dotfiles='cd ~/Settings_Linux/scripts; bash store_dotfiles.sh; cd -' -
To refresh your shell session and apply the new alias, type one of the following commands :
# Source the ~/.bash_aliases file source ~/.bash_aliases # Equivalently, use the custom alias: bash_refresh -
To store your new
~/.bash_aliasesfile, type the custom command alias:# store_dotfiles is an alias for 'cd ~/Settings_Linux/scripts; bash store_dotfiles.sh; cd -' store_dotfilesThis will store your
~/.bash_aliasesfile as the file~/Settings_Linux/sample_dotfiles/sample_DOTbash_aliases_<user>.txt, where<user>is your user name. -
In the event that your
~/.bash_aliasesfile is changed (by Adam or anyone else who applied the command aliassetup_all_homedirs), you can do one of the following:-
Restore your settings by typing the following command, where
<user>is your user name:# setup_dotfiles is an alias for 'bash setup_dotfiles.sh' # and setup_dotfiles.sh is located in /usr/local/bin setup_dotfiles <user> -
Compare your new settings with your previously saved settings and edit with vim, where
<user>is your user name:vimdiff ~/.bash_aliases ~/Settings_Linux/sample_dotfiles/sample_DOTbash_aliases_<user>.txt
-