Linux alias Command: Create Command Shortcuts
alias is a built-in command in Bash that assigns a short name to long commands or frequently used option combinations. You can check the aliases defined in the current shell or create new ones, which is useful for reducing repeated input and making interactive work consistent.
Aliases are not programs that execute commands but functions that replace strings when the shell reads the command line. If you need to handle arguments or require multi-step logic, shell functions are more appropriate than aliases.
What is the alias command?
In Bash, if the first word of a simple command matches an alias name, that word is replaced with the registered string and then the command is interpreted. For example, if ll is defined as ls -alF, then ll /var/log is executed like ls -alF /var/log.
alias itself is a Bash built-in command. This article is based on Bash, and other shells like Zsh may have different expansion rules and configuration files.
Basic Syntax
alias [-p] [name[=value]...]
Running it without arguments prints all aliases defined in the current shell. If you only specify a name, you can check that alias, and by specifying name=value, you can create a new alias or change an existing value.
alias alias ll alias ll='ls -alF'
Checking current aliases
Print all aliases
alias
The output is generally in the format alias name='value', which can be re-entered. alias -p can also be used for the same purpose.
Check a specific alias
alias ls alias grep
If the specified name is not defined as an alias, an error message is displayed, and a failure status is returned. To check whether a command name is an alias, a function, or an executable, use type name.
Creating an alias
Since the value may contain spaces or shell metacharacters, it is generally safe to enclose it in single quotes.
alias ll='ls -alF' alias grep='grep --color=auto' alias ..='cd ..' alias logs='journalctl -xe'
Do not put spaces around =. If you write it like alias ll = 'ls -alF', it will not be interpreted as an alias definition.
Saving the alias for continued use
Aliases defined on the command line are only valid in the current shell process. To use them in a new terminal, you need to define them in the Bash startup file.
alias ll='ls -alF' alias update='sudo apt update && sudo apt upgrade'
In interactive Bash, it is usually added to the user's home ~/.bashrc. Depending on the distribution, ~/.bash_aliases may also be sourced from ~/.bashrc, so check the existing configuration structure first.
After modifying the file, you can either open a new shell or apply it to the current shell with the following command.
source ~/.bashrc
Practical alias examples
| Example | Purpose |
|---|---|
alias la='ls -A' |
Displays hidden files excluding . and ... |
alias c='clear' |
Clears the terminal screen with a short command. |
alias gs='git status' |
Quickly checks the status of a Git working tree. |
alias dfh='df -h' |
Displays file system usage in human-readable units. |
alias mkdir='mkdir -p' |
Creates all necessary parent directories. Be careful in a team environment as it changes the behavior of the existing command. |
How to run the original command
To temporarily skip an alias on a name where the alias applies, you can prefix the command with a backslash.
\ls
The command is useful for bypassing shell function lookup, but alias expansion happens before that, so generally the second word, like ls in command ls, is not subject to alias expansion unless command itself is an alias. To ensure you specify the executable, you can use the absolute path like /usr/bin/ls.
Use a shell function if arguments are needed
Aliases do not have the capability to insert the first argument received into a middle position. If you need to handle positional arguments as shown below, it is clearer to define a function.
mkcd() {
mkdir -p -- "$1" && cd -- "$1"
}
Arguments entered after an alias are appended as-is to the end of the expanded command. If the purpose is simply to add default options, aliases are suitable, but if conditionals, loops, or argument validation are needed, use a function.
When an alias does not expand
Non-Interactive Shells and Scripts
Bash does not expand aliases in non-interactive shells by default. You can change this with shopt -s expand_aliases, but in scripts, using functions or explicit commands rather than aliases is better for portability and predictability.
Defining and executing on the same line
Aliases are expanded when Bash reads the command, not at execution time. Therefore, an alias defined on the same line or within a single compound command may not apply to the immediately following command.
alias hi='printf "hello\n"'; hi
To avoid confusion, place alias definitions on a separate line, and use functions or commands in script logic.
Criteria for safe use
- Avoid aliases that hide dangerous operations like deletion or overwriting.
- When using names that are the same as built-in commands, be aware that the behavior may differ.
- Ensure that server operation procedures or shared scripts do not rely on personal aliases.
- Use functions when complex quote handling, pipelines, and argument processing are required.
- Check the actual definition of an alias with
alias nameortype name.
Comparison of alias, function, script
| Method | Suitable uses | Cautions |
|---|---|---|
alias |
Add short names or default options in an interactive shell | It is difficult to directly handle positional arguments and complex logic. |
| Shell functions | Arguments, conditional statements, and repetitive tasks requiring multiple commands | The current shell type and function definitions are required. |
| Execution script | Tasks that can be reused across different shells, users, and systems | File placement, execution permissions, and PATH management are needed. |
Frequently Asked Questions
I created an alias, but it disappears in the new terminal.
Aliases created from the command line exist only in the current shell. Save them in ~/.bashrc or the alias configuration file used by your distribution, and start a new shell.
Can I include arguments in the alias name?
The arguments entered after an alias are appended to the end of the expansion, but you cannot specify their position like $1. If you need to specify the argument position or perform validation, use a shell function.
How do I delete an alias?
In the current shell, use unalias name. If the alias is stored in a startup file, you must also delete or comment out that definition to prevent it from being recreated in a new shell.









