Alias Command in Linux - With Examples

Linux users often have to use the same command many times. This reduces productivity and makes users easily bored or distracted.

So the alias command is generated which helps us to create aliases for the commonly used commands. This command is like a shortcut to help reduce working time and make the working process more efficient.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux commands queries.

In this context, we shall look into how to create aliases and use the alias command.


Linux alias syntax

Its syntax is given below:

$ alias [-p] [name[=value] ... ]

To list defined aliases, run the command:

$ alias


How to create aliases ?

Here, you will learn 2 different types of aliases are temporary and permanent. 

1. Creating temporary aliases

The command is:

$ alias name="value"

For example, We will create an alias for the command "sudo apt update" named "update":

$ alias update="sudo apt update"

Then run the command "update":

$ update


2. Creating permanent aliases

To keep the alias permanent between sessions, we have to save it in the shell configuration profile file.

Firstly, open the .bashrc file:

$ vim ~/.bashrc

If we want to create an alias for the command "cd /home" named "HH", We will run a demo:

$ HH


How to remove aliases ?

The command to do this is:

$ unalias [alias name]

For example, if we want to remove the alias "update", the we can execute:

$ unalias update


[Need assistance in fixing Linux system firewall configuration ? We can help you. ]

This article covers how to create aliases and use the alias command in Linux. In fact, the alias command instructs the shell to replace one string with another when executing commands. Aliases are used to customize the shell session interface. Using alias, frequently-used commands can be invoked using a different, preferred term; and complex or commonly-used options can be used as the defaults for a given command.

Related Posts