How to Set Up Shortcut Commands with Alias in Linux
Explanation
An alias is a feature that assigns a short name to a long or frequently used command, so that the original command can be executed just by using that name. It reduces the amount of typing for commands you enter repeatedly, improving your work efficiency.
Code
Write it after the alias command in the form alias_name='command'. Note that there must be no spaces on either side of the equals sign =.
alias ll='ls -alF'
Now, entering ll runs ls -alF.
# 코드
ll
# 출력
total 12
drwxr-xr-x 2 user user 4096 Jun 12 09:00 ./
drwxr-xr-x 5 user user 4096 Jun 12 08:55 ../
-rw-r--r-- 1 user user 23 Jun 12 09:00 memo.txt
You can also bundle options or multiple commands together.
alias update='sudo apt update && sudo apt upgrade'
Checking Configured Aliases
If you enter just alias with no arguments, you can see the list of currently configured aliases.
# 코드
alias
# 출력
alias ll='ls -alF'
alias update='sudo apt update && sudo apt upgrade'
How to Remove an Alias
Use the unalias command to remove a configured alias.
unalias ll
To remove all configured aliases at once, use the -a option.
unalias -a
Setting It Up Permanently
An alias set directly in the terminal as above is valid only in the current session and disappears when you close the terminal. To use an alias permanently, add it to the shell configuration file ~/.bashrc (or ~/.zshrc if you use zsh).
echo "alias ll='ls -alF'" >> ~/.bashrc
After modifying the configuration file, use the source command to apply the changes to the current session immediately. It is applied automatically when you open a new terminal.
source ~/.bashrc
