xxxxxxxxxx
# open .bashrc to add your alias
nano ~/.bashrc
# add your alias
alias alias_name="command_to_run"
# activate the alias for the session
source ~/.bashrc
xxxxxxxxxx
Basic syntax:
alias abbreviated_command='original -long -command'
# Example process:
1. Open the .bashrc file with your favorite shell text editor. E.g.
type "vi ~/.bashrc"
# Note, in general, the .bashrc file should be in your home
# directory. Type "cd ~" and then "ls -a" to confirm that it's there
2. Define an alias on a new line using this basic syntax:
alias abbreviated_command='original -long -command'
E.g.: alias ls='ls --color -lhAFG'
3. Save and exit the .bashrc file (e.g. type ":q" and Enter in vi/vim/nvim)
4. Source the .bashrc file to apply/activate the alias. E.g.
type "source ~/.bashrc"
# Note, I like having the following aliases to speed up this process:
alias bashrc='vi ~/.bashrc'
alias sourcebash='source ~/.bashrc'
xxxxxxxxxx
# cat script.sh
#!/bin/bash
# Script to check the alias output
shopt -s expand_aliases
alias ls1='ls -lrt'
ls1
xxxxxxxxxx
alias up='sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt dist-upgrade -y'
xxxxxxxxxx
#What this alias does:
#1.Creates a new file named 'new_script'
#2.Appends a shebang '#!/bin/bash' to first line of 'new_script' (be sure to swap example shebang with YOUR specific shebang [use 'which bash' to see yours]
#3.Makes 'new_script' executable
#4.lists current working directory in a tree form [on commandline input- 'sudo apt install tree' if you dont have it]
alias newscript="echo 'Creating new script...' && echo '#!/example/shebag/bin/bash' > new_script && chmod +x new_script && tree"