Linux Alias Tutorial

Linux is a command line-based operating system even though it provides GUI. The bash provides the environment to run commands. Linux provides lots of commands some of them are hard to remember or hard to type. The Linux bash provides the alias in order to shorten or rename commands. In this tutorial, we examine how to list, create and use an alias.

List alias

The alias command is used to list existing and active alias via the command-line interface. Simply the alias command searched for bash configuration files and extracts the lines those starts with the alias keyword. Apart from the alias command the alias keyword is used to define an alias in bash configuration files.

$ alias
List alias

As we can see there are different aliases for different commands. The following example shows the ls related alias which is named as la .

alias la='ls -A'

This alias can be called with the la which actually calls the ls -A command.

$ la

Create Temporary Alias

The alias keyword can be used to create alias in a temporary manner. The syntax of the alias keyword is like below.

  • ALIAS is the new alias used to call COMMAND.
  • COMMAND is the command which will be called with the ALIAS. The COMMAND can include parameters or options.

The alias command is not saved into bash configuration files and is lost after a reboot. In the following example, we create an alias with the name of mycd in order to navigate to the /mnt .

$ alias mycd = "cd /mnt"

Then we can call simply running mycd like below.

$ mycd

Create Permanent Alias

Aliases created via the command-line interface using the alias keyword are not permanent and they are lost when the system is rebooted. In order to create permanent alias, the alias should be stored in the shell configuration files like below for different shell types.

  • Bash ~/.bashrc
  • Zsh ~/.zshrc

First, we open the bash configuration file with our favorite text editors like vim or nano.

$ vim ~/.bashrc

Then add the following line and save the file.

alias mycd = "cd /mnt"

Remove Alias

Existing alias can be removed by using the unalias command. The unalias command syntax is like below.

unalias ALIAS

In the following example, we remove the alias named mycd .

unalias mycd

Leave a Comment