The Linux terminal is a treasure trove for power users, allowing you to perform numerous operations through the command line. However, some of these regularly used commands can be long or complex, due to which typing them out each time may not be the best option.

Is there a shortcut that you can use to assign a keyword to long commands and execute them using that keyword? With aliases, you can do that. This article will teach you how to set up, use, and remove Linux command line aliases.

What Is the alias Command?

The alias command in Linux allows you to define your own short keywords for long strings including commands which you execute frequently. With aliases, you can save yourself some time and energy while focusing on the task at hand without having to memorize the command. Aliases can be temporary as well as permanent.

Temporary aliases are active only for the current shell or terminal session. Therefore, if you open a new terminal or close the current window, these aliases will stop working. Temporary alias come in handy if you want to set aliases for a short duration of time or for a particular project.

On the other hand, permanent aliases will persist even if you close the current terminal or reboot your computer. So, if you see yourself using a command like sudo apt-get update frequently, setting up a permanent alias for it can be beneficial.

Setting Up Aliases With alias

Before you set up any aliases, it is good to ensure that your custom keyword doesn't conflict with any other Linux command such as lscd, or mkdir. To create an alias, open up the terminal on your Linux machine and use the following syntax:

        alias your_keyword = "some_linux_command"
    

For example, if you want to set an alias to change the current directory to the /MakeUseOf folder inside your /home directory and list the contents of the folder, you can set up an alias instead of executing cd /home/username/MakeUseOf and then ls.

        alias muo="cd /home/username/Projects && ls"
    
Linux Alias Command Demo

This method will only create temporary aliases and will not persist over different terminal sessions or reboots. To set up a permanent alias, you will need to edit the .bashrc config file if you use the bash shell or .zshrc config file if you use the Z shell.

You can do this using the built-in Vi text editor or any other text editor of your choice. Open the appropriate configuration file and add an alias using the same syntax used for temporary aliases. Once done, save the config file and start a new instance of the terminal for the changes to take effect.

Setting permanent aliases in Linux

You can also view all the aliases that have been set on your Linux machine using the alias command in this manner:

        alias
    
View all aliases on Linux

Removing Aliases With unalias

Removing temporary alias does not require you to do anything. Simply close the existing terminal session and open a new one to get rid of all temporary aliases. However, the process of removing permanent alias is similar to adding them in the first place.

Open up the config file you edited while adding the alias and remove the line where the alias is defined. Once done, save the file and start a new terminal instance. For temporarily disabling an alias, you can use the unalias command as well.

        unalias your_keyword
    
Linux unalias command

Make Your Linux Experience More Productive

Linux can help you take your productivity to the next level by providing handy commands like alias and unalias. By creating aliases, you can assign a short keyword to lengthier commands that you execute more often. This way, you can save time and effort while working efficiently on your computer.

However, that is not all. With some tips and tricks, you can become a Linux power user and make the most out of your computer.