alias
100%

Command Line · Lesson 18

alias

Learn how to create, inspect, persist, bypass, and remove command aliases in Bash.

An alias tells an interactive shell to replace one command word with another string before executing the line. This can shorten a frequent command or provide a preferred set of options.

Creating an Alias in the Current Shell

In Bash, define an alias with alias NAME='REPLACEMENT'. Do not put spaces around the equals sign:

$ alias ll='ls -la'

After this definition, entering ll as a command expands to ls -la. The quotes keep the replacement together while the alias is being defined.

Aliases are best for simple command-prefix substitutions. Use a shell function when you need to process arguments in a more structured way.

Which Bash command defines ll as an alias for ls -la in the current shell?

Loading an Alias in Future Bash Sessions

An alias defined at the prompt belongs to the current shell and disappears when that shell exits. Interactive non-login Bash sessions normally read ~/.bashrc, so that file is the usual place for personal Bash aliases:

alias ll='ls -la'

After editing the file, start a new interactive Bash session or reload it in the current shell:

$ source ~/.bashrc

Shell startup behavior can vary by shell, login mode, and distribution configuration. A Zsh user, for example, would normally use Zsh configuration rather than Bash's .bashrc.

Where should a personal alias normally be defined so future interactive non-login Bash sessions load it?

Inspecting Aliases and Name Resolution

Run alias without arguments to list aliases in the current shell:

$ alias
alias ll='ls -la'
alias grep='grep --color=auto'

Use type NAME to inspect how Bash resolves a particular name:

$ type ll
ll is aliased to 'ls -la'

Which command shows whether Bash currently resolves ll as an alias, function, builtin, or executable?

Bypassing and Removing an Alias

To bypass an alias for one command line, prefix the command name with a backslash or put it after Bash's command builtin:

$ \ls
$ command ls

This is useful when you need the underlying command's normal behavior. Keep aliases short and predictable, and avoid hiding surprising or destructive behavior behind familiar command names.

The current Bash session has an alias named ls. Which command bypasses that alias for one invocation?

Remove an alias from the current shell with unalias:

$ unalias ll

If the definition remains in ~/.bashrc, a future shell can create it again. Remove or change that configuration line as well when you want the alias gone permanently.

Which command removes the alias ll from the current Bash session?

Lesson complete

You finished alias

You can now customize Bash with simple, inspectable aliases.

  • Define a temporary alias with correct quoting.

  • Load personal aliases from ~/.bashrc in future sessions.

  • Inspect aliases and command resolution.

  • Bypass an alias for one invocation.

  • Remove both the active and saved definition when required.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Command Line