Glossary

Alias

An alias is a shell feature that substitutes one word with another when a command is typed interactively. Aliases are a cheap way to give long or frequently used commands short names, override default options, or even "rename" a command to something more memorable.

alias ll='ls -lah'
alias gs='git status'
alias grep='grep --color=auto'
alias ..='cd ..'
alias ...='cd ../..'

Typing ll then runs ls -lah. Aliases are expanded only as the first word of a simple command; they do not recurse into arguments or within scripts (unless shopt -s expand_aliases is set in bash). To see current aliases, run alias; to remove one, unalias ll.

Aliases belong in ~/.bashrc, ~/.zshrc, or a file sourced from there (a common convention is ~/.bash_aliases). They differ from functions, which can take arguments and run multi-line logic, and from shell scripts, which exist as files and produce a subshell. For anything more than the simplest substitution, a function is usually the right tool.

Related terms: Shell, bash

Discussed in:

Also defined in: Textbook of Linux