The Linux Alias command: Making Your Own Custom Shell Command Shortcuts
Published: 2022-06-27 20:19:59

## Are you tired of using the same set of Linux commands repeatedly? Or find it difficult to navigate to a frequently visited file? There’s an easy solution — the *alias* command.

![Photo by [卡晨](https://unsplash.com/@awmleer?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/coding-laptop?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)](https://cdn-images-1.medium.com/max/7474/1*boQe_qSM7ZKdgQsNqB_zOw.jpeg)


The alias command is a shell command that allows users to create a shortcut in place of another command. It’s useful for simplifying command names, replacing commands with preferred names, and allowing easy navigation around the shell.

The created shortcut can be temporary or permanent, and is removable either way.

In this tutorial, I will show you how to create, remove, and make aliases permanent.

***Requirements: Bash Shell, any Linux text editor, and a basic understanding of the shell terminal.***

Let’s get started!

## **The Alias Command Syntax**

![](https://cdn-images-1.medium.com/max/2000/1*_YOomrPd-v2O2RYQNaSNfw.jpeg)

 **alias**: It calls the alias command.

* **option**: Alias has only two options:

i. -p: **displays all current aliases (created shortcuts)*

ii. -a: removes all current aliases.

* **name**: preferred shortcut (alias) name

* **value**: the command/syntax

**Examples**

**Creating a shortcut for the _clear_ command**

![](https://cdn-images-1.medium.com/max/2000/1*hFw78FGGC86NffX33qhvEQ.png)

This enables the user to use **c** in place of the **clear** command.

**Assigning a shortcut to a command and its frequently used option**

![](https://cdn-images-1.medium.com/max/2000/1*OAmibcpJgeKhABVt4XqW3A.png)

The **ls** command allows users to list files, while **ls -la** list files in long format including hidden files. A user might prefer the second command. By assigning the **ls** command to **ls -la**, invoking **ls** will list all files in long format.

**Navigating to a directory/file** 
![](https://cdn-images-1.medium.com/max/2000/1*oR-thkQx2JyNYnwias4pfQ.png)

The above command allows the user to navigate to **root/my_very_long_directory** using just **ct**.

This is the power of the alias command. Instead of having to remember the name of the directory or typing the directory name (of course you can use the Tab key to auto complete the directory name), you can set the path of the directory to an alias.

### **Creating a permanent alias**

The above examples only allow you to use the aliases for the time you’re working on your shell. Once you close the shell, the aliases are cleared from the terminal’s memory.

To create a permanent alias follow these steps:

* Use your favorite editor (vi, nano e.t.c) to create a file called **~/.bash_aliases.**

![](https://cdn-images-1.medium.com/max/2000/1*jgCXOfGKbUNr70wZLAhYdA.png)

* Type the alias command into the file.

![](https://cdn-images-1.medium.com/max/2000/1*MEaDJhIxqfLGTn9zzxSUvg.png)

* Save and exit.

* The shell will execute on restarting or logging in to your terminal. To execute immediately, type “..bash_aliases”.

![](https://cdn-images-1.medium.com/max/2000/1*4rSCLUB0ULLB5dNFuU4J5w.png)

* You can now use your alias command permanently.
**Note: if “..bash_aliases” does not work, use "source .bash_aliases".**

### Removing Aliases

The unalias command is used to remove aliases.

* To remove all aliases

![](https://cdn-images-1.medium.com/max/2000/1*tG0w18iz9UPQNqjAz0zVOQ.png)

This removes all the aliases.

* To remove a specific alias

![](https://cdn-images-1.medium.com/max/2000/1*LgcWMRorsCyaoWMWYGUQBg.png)

**Example**

![](https://cdn-images-1.medium.com/max/2000/1*ZzNWaIe3Qj5dVlqel2QKIg.png)

Removes the created shortcut for the **clear** command.

### Conclusion

The Linux alias command enables you to create useful and powerful shortcuts that make your work easier on the shell terminal. You’ve learnt what an alias is, how to create one, make it permanent and remove it. You can now create your own shell command shortcuts.