alias Command
Beginner Shell Scripting man(1)Create command shortcuts
👁 8 views
📅 Updated: Mar 15, 2026
SYNTAX
alias [NAME[=VALUE]]
What Does alias Do?
alias creates shortcuts for commands or command sequences. An alias replaces a word with a string when used as the first word of a command. Aliases save typing and reduce errors for frequently used commands.
alias is a shell built-in that defines command shortcuts for the current session. For permanent aliases, add them to ~/.bashrc or ~/.bash_aliases. Aliases can be simple substitutions or include complex command options.
Aliases are expanded only when used as the first word of a command. They do not work inside scripts (bash disables alias expansion in non-interactive mode by default).
alias is a shell built-in that defines command shortcuts for the current session. For permanent aliases, add them to ~/.bashrc or ~/.bash_aliases. Aliases can be simple substitutions or include complex command options.
Aliases are expanded only when used as the first word of a command. They do not work inside scripts (bash disables alias expansion in non-interactive mode by default).
Options & Flags
| Option | Description | Example |
|---|---|---|
| (no args) | List all current aliases | alias |
| name=value | Create an alias | alias ll='ls -la' |
| unalias | Remove an alias | unalias ll |
Practical Examples
#1 List all aliases
Shows all currently defined aliases.
$ alias
Output:
alias ll='ls -la'
alias la='ls -A'
#2 Create simple alias
Creates a shortcut for system updates.
$ alias update='sudo apt update && sudo apt upgrade -y'#3 Create ls shortcut
Creates a detailed listing shortcut with human-readable sizes.
$ alias ll='ls -lah --color=auto'#4 Safety aliases
Adds confirmation prompts to destructive commands.
$ alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'#5 Make alias permanent
Adds the alias to .bashrc and reloads it.
$ echo "alias ll='ls -la'" >> ~/.bashrc && source ~/.bashrc#6 Remove an alias
Removes the rm alias, restoring the original command.
$ unalias rm#7 Bypass alias temporarily
Prefixing with backslash runs the original command, ignoring the alias.
$ \rm file.txtTips & Best Practices
Bypass an alias: Prefix with backslash to skip alias expansion: \rm file.txt runs /bin/rm even if rm is aliased to rm -i.
Permanent aliases: Add aliases to ~/.bashrc or create ~/.bash_aliases (sourced by many default .bashrc files). Run source ~/.bashrc to apply.
Aliases do not work in scripts: Bash disables alias expansion in non-interactive mode (scripts). Use functions instead of aliases in scripts.
Frequently Asked Questions
How do I make an alias permanent?
Add it to ~/.bashrc: echo "alias ll='ls -la'" >> ~/.bashrc. Then source ~/.bashrc to apply immediately.
How do I remove an alias?
Use unalias name. For example: unalias ll. To bypass temporarily, use \command.
Should I use aliases or functions?
Aliases are simple command shortcuts. Functions support arguments, logic, and work in scripts. Use functions for anything complex.
Related Commands
More Shell Scripting Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →