The command line is wonderfully efficient, until you find yourself typing the same long command for the hundredth time.
For example:
ls -alF
If you use it frequently, Bash lets you give it a shorter name:
alias ll='ls -alF'
Now you can simply type:
ll
This is a shell alias: a name that Bash expands into another command when you use it.
Aliases are primarily an interactive-shell convenience. They are excellent for short, frequently used commands, while functions and scripts are better suited to more complicated operations.
Creating an alias
The basic syntax is:
alias name='command'
For example:
alias ll='ls -alF'
You can create aliases for practically any simple command line:
alias c='clear'
alias h='history'
alias la='ls -A'
alias ports='ss -tulpn'
alias gs='git status'
After defining:
alias gs='git status'
you can run:
gs
and Bash expands it to:
git status
Arguments can be added normally:
gs --short
which becomes:
git status --short
This makes aliases particularly useful for commands where the basic command and options stay the same but the arguments change.
Listing aliases
Run alias without arguments:
alias
Bash will display the aliases currently defined in the shell.
For example:
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
The exact list depends on your shell configuration and operating system.
To inspect one particular alias:
alias ll
You might get:
alias ll='ls -alF'
The -p option explicitly requests the reusable alias format:
alias -p
Finding out what a command really is
When troubleshooting a shell, type is often more useful than alias.
For example:
type ls
might report:
ls is aliased to `ls --color=auto'
This is useful because a command name in Bash can refer to different things: an alias, function, builtin, or external executable.
You can also use:
type -a ls
to show all matching definitions Bash can find.
Another useful form is:
command -V ls
If something behaves differently from what you expect, checking it with type is a good first diagnostic step.
Removing an alias
Use unalias to remove an alias:
unalias ll
After that, ll is no longer defined as an alias in the current shell.
To remove all aliases:
unalias -a
Be careful with this one—it removes every alias currently defined in the shell.
If the aliases are defined in ~/.bashrc, they will normally come back the next time that configuration is loaded.
Temporarily bypassing an alias
Sometimes you want to execute the original command rather than its alias.
Suppose:
alias ls='ls --color=auto'
You can bypass the alias with:
\ls
The leading backslash prevents alias expansion.
You can also use:
command ls
This tells Bash to execute the command while bypassing alias expansion.
These techniques are useful when debugging a shell configuration or when you deliberately want the unmodified command.
Making aliases permanent
An alias created interactively normally exists only in the current shell session:
alias ll='ls -alF'
If you close that shell, the definition is gone.
For aliases you want to use regularly, put them in your Bash startup configuration, commonly:
~/.bashrc
For example:
# ~/.bashrc
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias c='clear'
alias gs='git status'
alias ports='ss -tulpn'
After changing .bashrc, reload it:
source ~/.bashrc
or:
. ~/.bashrc
Your aliases will then be available in the current shell.
Useful everyday aliases
A typical interactive Bash configuration might contain:
# Directory listing
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
# Git
alias gs='git status'
alias gd='git diff'
alias gl='git log --oneline --graph --decorate'
# Docker
alias dps='docker ps'
alias dimg='docker images'
# Miscellaneous
alias c='clear'
alias h='history'
There is no universal list of “correct” aliases. They should solve annoyances that actually occur in your own workflow.
If you use a command ten times a day, shortening it may make sense. If you use it once a year, perhaps Ctrl+C is not required yet.
Aliases with command options
One of the most common uses of aliases is establishing convenient defaults.
For example:
alias grep='grep --color=auto'
Now:
grep error logfile.txt
is effectively processed as:
grep --color=auto error logfile.txt
Another example is making potentially destructive commands interactive:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
This causes these commands to ask for confirmation in situations where the underlying command's -i option applies.
Whether you want such aliases is a matter of personal workflow, but remember that they modify your interactive environment. A command that behaves one way on your laptop may behave differently on another machine.
When in doubt:
type rm
Aliases versus functions
Aliases are intentionally simple.
They work well for things like:
alias ll='ls -alF'
alias gs='git status'
But suppose you want to create a helper that accepts arguments and performs several operations:
mkcd() {
mkdir -p -- "$1" &&
cd -- "$1"
}
Now:
mkcd projects
creates the directory and changes into it.
This belongs in a function rather than an alias.
A useful rule is:
If it is a short command shortcut, use an alias. If it needs logic or argument handling, use a function.
For larger or reusable automation, use a script.
Why aliases are usually not appropriate for scripts
Aliases are primarily intended for interactive command-line use.
You should not normally write a script like this:
#!/usr/bin/env bash
ll
and assume that ll exists.
A non-interactive Bash shell does not normally load your interactive aliases in the same way your terminal shell does.
A script should generally use the actual command:
ls -alF
rather than relying on a personal shortcut from .bashrc.
This makes the script self-contained and portable between machines.
There are ways to enable alias expansion in scripts, but that is rarely the right solution. If a script needs reusable command logic, functions or separate scripts are much clearer.
Aliases and quoting
You will usually see aliases defined with single quotes:
alias ll='ls -alF'
This is a convenient way to preserve the command text while defining the alias.
Double quotes also work for simple definitions:
alias ll="ls -alF"
The difference becomes important when the alias definition contains shell expansions.
For example:
alias today='date "+%Y-%m-%d"'
Using single quotes keeps the definition from being expanded by the current shell while you create it.
For ordinary aliases, the simple pattern:
alias name='command'
is usually the clearest choice.
The BASH_ALIASES array
Bash also provides an associative array named:
BASH_ALIASES
It gives shell code programmatic access to aliases.
For example:
alias ll='ls -alF'
Then:
echo "${BASH_ALIASES[ll]}"
returns:
ls -alF
You can inspect the array with:
declare -p BASH_ALIASES
This can be useful for scripts or interactive shell customization that needs to inspect aliases programmatically.
BASH_ALIASES is Bash-specific, so it should not be expected to exist in other shells.
A practical example
Let's say you frequently inspect system logs.
Instead of repeatedly typing:
ls -lah /var/log
define:
alias logs='ls -lah /var/log'
Now:
logs
is enough.
You could also create:
alias journal-errors='journalctl -p err -b'
and:
alias listening='ss -tulpn'
Your interactive workflow becomes:
logs
journal-errors
listening
These aliases don't replace the underlying commands. They simply give you convenient names for command lines you already know and use.
Troubleshooting
If an alias isn't working, check whether it exists:
alias ll
Then ask Bash what the name resolves to:
type ll
If you defined it in .bashrc, check that the definition is actually there:
grep -n 'alias ll' ~/.bashrc
Then reload the configuration:
source ~/.bashrc
If you're still unsure whether your startup configuration is responsible, start a clean Bash shell:
bash --noprofile --norc
This starts Bash without reading the usual startup files.
You can then compare the behavior with your normal shell.
A note about sudo
Aliases can be slightly confusing when combined with sudo.
For example, if you have:
alias ll='ls -alF'
then:
ll
works because ll is the command name Bash sees and expands.
But:
sudo ll
does not simply mean:
sudo ls -alF
because ll is no longer the command name at the position where Bash performs normal alias expansion.
If you need a privileged version of a frequently used operation, a function or an explicit command is often clearer.
Bash's built-in help
Because alias is a Bash builtin, you don't need to search the internet every time you forget its syntax.
Ask Bash itself:
help alias
You can also check:
help unalias
This is particularly useful when working on a different Bash version or machine.
Quick reference
# Create an alias
alias ll='ls -alF'
# List all aliases
alias
# Show one alias
alias ll
# List aliases in reusable form
alias -p
# Find out what a command is
type ll
# Remove an alias
unalias ll
# Remove all aliases
unalias -a
# Reload Bash configuration
source ~/.bashrc
# Inspect aliases programmatically
declare -p BASH_ALIASES
# Show Bash's documentation
help alias
Conclusion
The alias builtin is one of those Bash features that is easy to understand and surprisingly useful.
The basic idea is simple:
alias ll='ls -alF'
followed by:
ll
Use aliases for small, frequently used interactive shortcuts. Keep more complicated behavior in functions or scripts, where arguments, logic, and error handling can be expressed explicitly.
Once you start building your own shell environment, a handful of well-chosen aliases can save a remarkable amount of typing.
And if you ever forget what some mysterious command in your terminal actually means, remember the magic spell:
type command
Because sooner or later, every .bashrc becomes a small archaeological site.