Alias Frequently Used Commands in Linux

Updated by Linode Written by Edward Angert

Contribute on GitHub

Report an Issue | View File | Edit File

What is an Alias?

An alias is a custom shortcut set to represent a set of commands or a single command run with specific options. Use an alias to execute frequently used processes with as little as a single character.

List Existing Aliases

alias

Where to Find and Edit Aliases in Bash, Z shell (ZSH), and fish

The Bash shell is the default on most modern operating systems. If using ZSH, oh-my-zsh or fish, the shell’s configuration file may be in another location. Based on the shell in use, the configuration profile will be found in:

  • Bash: ~/.bashrc
  • ZSH: ~/.zshrc
  • fish: ~/.config/fish/config.fish

Create a Temporary Alias

Aliases can be created through the command line using the syntax alias customName="commands the alias should run". For example:

alias webroot="cd /var/www/html/example.com/public_html"

Remove an Alias

Any alias added through the command line can be unaliased using unalias:

unalias testalias

Create a Permanent Alias

To create a persistent alias, edit the configuration profile for your shell and add the alias to the end of the file:

~/.bashrc
1
2
3
...
alias la="ls -al"
...

Refresh the Configuration

source the configuration file to refresh the configuration changes:

source ~/.bashrc

Alias Existing Linux Commands

Existing Linux commands can be aliased to run with frequently-used options. As with any alias, this should be used with caution as once a user is accustomed to the results of the alias, the user may expect the same results on other machines or terminals where the alias may not exist.

In this example, change the default behavior of the ls command to provide more information about files and directory structure:

alias ls="ls -aFhl"

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

comments powered by Disqus

This guide is published under a CC BY-ND 4.0 license.