VMware ESXi and vSphere Cluster Management

Create and Manage Linux Shell Aliases

Learn how to create, view, customize, persist, and remove Linux shell aliases with alias and unalias.

A shell alias is a shortcut defined by your command interpreter. It gives a memorable name to another command, a command with options, or a sequence of commands. For example, you can make dir run ls -l.

Aliases reduce typing and let you apply preferred options automatically. They are interpreted by the shell, such as Bash or Zsh, rather than being standalone executable programs. When you type an alias name, the shell performs command expansion: it replaces the alias name with its configured command text before execution.

Alias syntax

The general syntax for creating an alias is:

alias NAME='command [options]'

The parts have these roles:

  • alias is the shell command that creates or displays aliases.
  • NAME is the shortcut you will type later.
  • = connects the name to its expansion. Do not put spaces around the equals sign.
  • The quoted value contains the command, options, and, when needed, several commands.

Quoting is important because the expansion can contain spaces, options, or command separators. Without quotes, the shell may interpret parts of the intended expansion as separate arguments to alias. Single quotes are commonly used because they preserve the command text while the alias is being defined.

Create a simple command shortcut

The following alias creates a familiar directory-listing shortcut:

alias dir='ls -l'

ls lists directory contents, and -l requests the long format, which includes additional file details. Users familiar with the dir command on other operating systems may find this name convenient.

After defining it, invoke the alias by typing its name:

dir

The shell expands dir to ls -l, so the result is a long-format listing of the current directory.

Run multiple commands from one alias

An alias can contain a command sequence. A semicolon is a command separator; it places one command after another in the same shell input:

alias dir='ls -l; pwd'
dir

When you type dir, the shell first runs ls -l and then runs pwd. The practical result is a long-format directory listing followed by the path of the current working directory.

The commands execute in the order written. Be careful when placing commands with side effects in an alias, because a short name can conceal more activity than users expect.

Change the default behavior of a command

You can define an alias with the same name as an existing command:

alias ls='ls -l'

In the current interactive shell, typing ls now expands to ls -l, so long-format output becomes the default. This can make a preferred workflow faster and more consistent.

Redefining familiar commands also has a caution: someone reading your command may expect the normal behavior of ls but receive the alias behavior instead. This matters especially on shared systems, when following instructions, or when diagnosing a problem.

To run the underlying command without the alias, use:

command ls

List aliases

Run alias without arguments to display the aliases currently defined in the shell:

alias

The output identifies each alias name and its command expansion. For example, an entry may look like this:

alias dir='ls -l'
alias ls='ls -l'

To inspect one alias, provide its name:

alias dir

This displays the definition when supported by the current shell, including Bash and Zsh.

Remove aliases

Use unalias to remove an alias from the current shell session:

unalias dir

unalias is a shell command that deletes a previously defined alias. Verify the removal by listing the definition:

alias dir

If the alias was removed, the shell reports that no such alias is defined. You can also try typing dir; it will no longer expand to the custom command.

To remove every alias in the current shell, use the following operation with caution:

unalias -a

This can remove aliases you did not create and may change the behavior of the rest of your session. Usually, removing a specific alias is safer.

Common alias management commands

Task — Command pattern — Result

Create an alias — alias NAME='command [options]' — Defines a shortcut in the current shell.

List all aliases — alias — Displays the aliases currently available.

Display one alias definition — alias NAME — Shows the expansion for a named alias, where supported.

Remove one alias — unalias NAME — Deletes one alias from the current shell.

Remove all aliases — unalias -a — Deletes every alias in the current shell; use with caution.

Temporary aliases and persistent aliases

An alias created directly at a prompt normally exists only in the current shell session, meaning the active terminal shell in which you defined it. Closing that shell or opening a separate terminal usually removes the temporary definition.

For persistent behavior, place the alias definition in a startup file. A startup file is a shell configuration file read when a shell starts. The appropriate file depends on the shell:

Definition location — How long it lasts — Typical use — Configuration file examples

Current interactive shell — Until that shell exits — Testing an alias or using it temporarily — No file required.

Bash startup configuration — Future interactive Bash sessions after the file is loaded — Reusable Bash aliases — ~/.bashrc.

Zsh startup configuration — Future interactive Zsh sessions after the file is loaded — Reusable Zsh aliases — ~/.zshrc.

For Bash, append an alias definition to ~/.bashrc with:

printf "alias ll='ls -l'\n" >> ~/.bashrc

New interactive Bash sessions can load the ll alias after reading that file. For Zsh, add the equivalent line to ~/.zshrc:

alias ll='ls -l'

If you edit a startup file while a terminal is already open, start a new shell or reload the appropriate file where appropriate. For example, Bash users commonly reload their file with:

source ~/.bashrc

Make sure you edit the file that matches the shell you are actually using. The command echo $SHELL can provide a clue, although the configured login shell and the currently running shell are not always identical.

Alias limitations and safe use

  • Aliases are mainly intended for interactive command-line use.
  • An alias defined at a prompt is not automatically available to other terminal sessions.
  • Aliases may not be expanded in scripts or other non-interactive shells unless alias expansion is explicitly enabled and the definition is loaded.
  • For scripts, prefer explicit commands or a shell function. This makes the script's behavior clearer and more predictable.
  • Avoid aliases that hide dangerous operations, especially commands that delete, overwrite, or modify many files.
  • Be cautious with aliases on shared systems, where another user may not know your custom command behavior.

Troubleshoot alias problems

An alias disappears in a new terminal

The alias was probably created only in the current shell session. Add it to the matching startup file, then open a new terminal or reload the file.

The expansion is incomplete or produces an error

Spaces or separators may not have been quoted correctly. Put the complete expansion inside quotes:

alias name='command option; other-command'

ls behaves differently than expected

An alias named ls may be overriding the normal interactive invocation. Inspect it with:

alias ls

Remove it with unalias ls if necessary, or bypass it for one command with:

command ls

An alias works interactively but not in a script

Aliases are generally not expanded in non-interactive shell contexts. Use the explicit command or a shell function in the script instead of relying on an interactive alias.

A persistent alias does not appear

The wrong startup file may have been edited, or the current shell may not have reloaded it. Confirm the active shell, edit its matching file, and start a new shell or source the file when appropriate.

Key points

  • An alias is a shell-defined shortcut, not a separate executable program.
  • Use alias NAME='command and options' to define one.
  • Quote expansions containing spaces, options, or multiple commands.
  • Use alias to list definitions and unalias NAME to remove one.
  • Prompt-created aliases are temporary unless stored in a startup file such as ~/.bashrc or ~/.zshrc.
  • Remember that aliases can change interactive behavior and are not a reliable mechanism for portable shell scripts.

For related command-line configuration, see Create and Manage Linux Shell Aliases.