Bash Aliases: Make Your Terminal Smarter with Shortcuts
You know the feeling: you type the same long commands over and over again—and a single typo can cost you time. With bash aliases, you can create your own terminal “shortcuts,” so you can type updateme instead of a full update routine. In just a few minutes, you can make your terminal faster, more personal, and much more pleasant to use—just like using bookmarks in your browser instead of typing https://stackoverflow.com every time 🥳
What is a bash alias?
An alias is a short name that “stands in” for a longer command. When you type the alias name, bash automatically replaces it with the full command.
- You type:
updateme - Bash runs:
sudo apt update && sudo apt full-upgrade -y
Aliases are perfect for:
- long commands you use often
- “safe defaults” (for example
rm -i) - quick navigation shortcuts (for example
..,...) - small workflows (for example git commands)
Tip: Aliases are mainly for interactive use. For more advanced logic (parameters, if/loops), a shell function is often better—but aliases cover 80% of the need.
Step by step: Create and use ~/.bash_aliases
1) Check whether you use bash
Run:
echo $SHELL
If you see something like /bin/bash, you are using bash.
2) Check whether ~/.bash_aliases exists
Run:
ls -la ~/.bash_aliases
If the file does not exist, we will create it in the next step.
3) Create or open ~/.bash_aliases
You can use whichever editor you prefer. Here are two easy options:
With nano (beginner-friendly):
nano ~/.bash_aliases
With vim (if you use it):
vim ~/.bash_aliases
Note:
~means your home directory (typically/home/yourname).
4) Add your first alias (for example updateme)
Paste this into ~/.bash_aliases:
alias updateme="sudo apt update && sudo apt full-upgrade -y"
Save and close the file:
- nano:
Ctrl + O, Enter,Ctrl + X - vim:
Esc, type:wq, Enter
5) Load aliases without restarting the terminal
Run:
source ~/.bash_aliases
Now the alias works immediately.
6) Test the alias
Run:
updateme
If everything is set up correctly, it will start your update.
Make sure ~/.bash_aliases loads automatically
On many Linux distributions, ~/.bash_aliases is loaded automatically through ~/.bashrc. But it is smart to check.
1) Open ~/.bashrc
nano ~/.bashrc
2) Find (or add) this block
It often looks like this:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
If it is missing, you can paste it at the bottom of the file.
3) Load ~/.bashrc
source ~/.bashrc
Tip: When
~/.bash_aliasesis loaded through~/.bashrc, your aliases are automatically ready in new terminal windows.
Awesome alias examples (ready to copy/paste)
Here is a collection of practical aliases you can add to ~/.bash_aliases.
1) Safer and more informative file handling
alias ll="ls -lah"
alias la="ls -A"
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
Why?
-iasks before overwriting/deleting (fewer accidents).llgives you a readable list with hidden files and sizes.
2) Quick navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias home="cd ~"
3) Updating and cleanup (Debian/Ubuntu)
alias updateme="sudo apt update && sudo apt full-upgrade -y"
alias autoremove="sudo apt autoremove -y && sudo apt autoclean"
Note:
apt full-upgrademay remove/change packages to complete the upgrade. That is often fine—but read the output, especially on servers.
4) Networking and quick troubleshooting
alias myip="curl -s ifconfig.me && echo"
alias ports="ss -tulpn"
alias pingg="ping -c 5 1.1.1.1"
Why?
myipshows your public IP.portsshows which services are listening on which ports.
5) Git aliases for everyday use
alias gs="git status"
alias ga="git add ."
alias gc="git commit -m"
alias gp="git push"
alias gl="git log --oneline --graph --decorate --all"
Then you can, for example, type:
gc "Fix login bug"
6) Quick environment “restarts”
alias reloadbash="source ~/.bashrc"
alias edits="nano ~/.bash_aliases"
Now you can:
- edit aliases with
edits - activate them with
reloadbash
How to avoid common mistakes
Always use quotes around the command
Correct:
alias updateme="sudo apt update && sudo apt full-upgrade -y"
Incorrect (can cause strange errors):
alias updateme=sudo apt update
Check what an alias is set to
Run:
alias updateme
Remove an alias temporarily
In the current terminal session:
unalias updateme
Note: If the alias is still in
~/.bash_aliases, it will come back the next time you open a new terminal (or runsource).
Name conflicts: When an alias “hides” a real command
If, for example, you have alias ls="ls -lah" and want to run the original ls, you can type:
\ls
The backslash means: “use the real command, not the alias.”
Summary
Bash aliases are a simple way to make your terminal faster and more pleasant:
- Create/open
~/.bash_aliases - Add aliases like
alias updateme="..." - Run
source ~/.bash_aliases(or reopen the terminal) - Make sure
~/.bashrcloads~/.bash_aliases
Once you start using aliases, they quickly feel like a superpower: fewer keystrokes, fewer mistakes, and more flow in your daily work. ⚡