A bash alias maps a short keyword to a longer shell command. Type less, run the same thing. Any command you repeat multiple times per session is a candidate — and setting one up takes under a minute.
How to Create a Bash Alias
The syntax is straightforward:
alias SHORTCUT="FULL COMMAND"
No spaces around the = sign. A typical example that maps ll to a detailed file listing:
alias ll="ls -l"
Run this in the terminal and ll works immediately. Close the window, and the alias disappears. That’s fine for testing — once you confirm it works, you can make it permanent.
Because a bash alias substitutes its name with the underlying command, you can append extra flags after it. ll -a expands to ls -l -a. You can also shadow an existing command by giving the alias the same name: alias ls="ls -F" appends a file-type symbol to every ls call going forward.
How to Make a Bash Alias Permanent
Aliases defined in the terminal are session-only. To load them every time you open a shell, add them to a startup configuration file. Two files handle this:
| File | Loaded During | Best For |
|---|---|---|
~/.bash_profile | Interactive login sessions | Aliases and functions used while logged in |
~/.bashrc | Non-login and subshell sessions | Aliases needed in scripts or spawned shells |
After editing either file, activate the changes in the current session:
source ~/.bash_profile
To append an alias without opening an editor, use shell redirection:
echo 'alias ll="ls -l"' >> ~/.bash_profile
When you need your PATH configured alongside your aliases, both go in the same file — order within the file generally does not matter for either.
Chaining Multiple Commands in One Bash Alias
Join commands with && to run them in sequence. Each step only fires if the previous one succeeds. A common Git shortcut:
alias gpm="cd $(git rev-parse --show-toplevel) && git checkout main && git pull"
This moves to the repository root, switches to main, and pulls — all from one short keyword. The $() syntax embeds executable statements inside the alias.
Practical Bash Alias Examples for Faster Workflows
Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
These become second nature fast. Pair them with the gt alias below for getting around a project quickly.
Git shortcuts
alias gt="cd $(git rev-parse --show-toplevel)"
alias gs="git status"
alias ga="git add ."
gt jumps to the project root from wherever you are. Keep alias names two to three characters — short enough to type reflexively. Understanding what the git stash command does helps when you want to alias multi-step save-and-switch operations too.
Process monitoring
alias cpu="top -o cpu"
alias mem="top -o rsize"
Shell config editing
alias bp="vim ~/.bash_profile"
Useful once your alias collection grows. One command to open and edit the file directly.
Utility shortcuts
alias cpwd='pwd|tr -d "\n"|pbcopy'
alias ip="curl icanhazip.com"
alias rmdbc="find . -name \"*(*'s conflicted copy*)*\" -exec rm {} \;"
cpwd copies the current directory path to the clipboard on macOS. ip checks your public IP. rmdbc removes Dropbox conflict files recursively.
When to Use a Shell Function Instead of a Bash Alias
An alias only appends arguments at the end. When you need to place an argument at a specific position in the command, a shell function handles it better:
gg() {
git commit -v -a -m "$*"
}
The $* token captures all arguments as a single string. Running gg fix login bug expands to git commit -v -a -m "fix login bug" — no manual quoting needed. You can learn more about how the shell processes these constructs from the bash built-in reference.
Inside a function, $1 refers to the first argument, $2 to the second, and so on. This lets you insert arguments mid-command — something a regular alias cannot do.
| Feature | Bash Alias | Shell Function |
|---|---|---|
| Accepts trailing arguments | Yes | Yes |
| Inserts arguments mid-command | No | Yes |
| Stored in startup files | Yes | Yes |
| Handles conditional logic | No | Yes |
Store functions in the same file as your aliases. They load automatically on every new session. If your collection grows large, a dedicated ~/.bash_aliases file keeps things cleaner — source it from ~/.bashrc with one line.
Removing a Bash Alias
Use unalias to remove one by name:
unalias ll
This removes it from the current session. To stop it loading permanently, delete the corresponding line from your ~/.bash_profile or ~/.bashrc as well. Running alias with no arguments lists every active alias currently defined in the session.
Using Bash Aliases in Shell Scripts
Aliases are not expanded in non-interactive scripts by default. To enable alias expansion inside a script, add this line near the top:
shopt -s expand_aliases
After that, any alias defined in the script body works as expected. This approach lets you reuse shorthand inside automated tasks. For more on how scripts execute in Linux, the shell script execution guide covers permissions and interpreter options in full. Text processing inside those scripts often relies on tools like bash cut to parse output before passing it along.
FAQs
What is a bash alias?
A bash alias maps a short keyword to a longer shell command. Typing the alias name runs the full command without retyping it each time.
How do I make a bash alias permanent?
Add the alias definition to ~/.bash_profile or ~/.bashrc, then run source ~/.bash_profile to load it in the current session.
Can a bash alias accept arguments?
Aliases accept arguments appended at the end only. To insert arguments mid-command, use a shell function with $1, $2, or $* instead.
How do I list all active bash aliases?
Run alias with no arguments in your terminal. It prints every currently defined alias along with its expanded command.
What is the difference between ~/.bashrc and ~/.bash_profile for aliases?
~/.bash_profile loads during interactive login sessions. ~/.bashrc loads for non-login and subshell sessions. Aliases placed in ~/.bashrc are available more broadly across session types.