How to Use the Alias Command in Linux

linux header image

In this tutorial you will learn how to create your own custom alias commands in Linux. Setting up a Linux alias is a very easy thing to do. Aliases are very beneficial as they save a lot of time, such as remembering long or complicated commands. We will be adding our own aliases by editing the “.bashrc” file. This tutorial will work on virtually all Linux distributions. Continue reading below to get started.

Open the Terminal

launch terminal in linux

The first thing you need to do is open a new Terminal window in Linux.

Edit the .bashrc File

edit bashrc

Once you have the new terminal window open, enter the command nano ~/.bashrc and press Enter. This will open your .bashrc file using the nano text editor. The .bashrc file is a script that runs every time you launch Bash. You can add commands here for customizing and automating your Linux environment. If you open the file and it is blank it means you do not already have it (the file). The file will be created once you save using Ctrl+X, press the Y key, then press Enter.

Add the Command Alias’s

add alias commands to bashrc file

Towards the top of your bashrc file you will want to add a few new lines. Afterwards you can begin typing your alias commands. The format to use is alias aliasname=”Linux Command”. For example one of my aliases is ‘alias pg=”ping google.com”‘. When the command “pg” is ran, it will ping Google. The possibilities with aliases are endless. After adding your custom aliases simply save and close the file.

Reload the Bash Configuration

reload bashrc

Next you will have to reload the .bashrc file to reload the changes you just made. To do this type “source ~/.bashrc” and press Enter. The alias is now ready to be used.

Test the Linux Alias’s

test the alias command

To use your custom Linux aliases type the command that was written for it. In my example I used “pg” to ping google.com. Above is an example of the custom alias command running.

Additional Questions?

If you have any additional questions or thoughts feel free to comment them below.

Related Resources

View our list of The Top 10 Programming Languages to Learn in 2022.

Learn How to Install Ubuntu Server 22.04 [Step by Step].

Click here to learn How to Install MySQL on Ubuntu Server 22.04 LTS.

View our Programming Articles and Tutorials.

Learn How to install and configure Nginx – Ubuntu 20.04.

View all of our available online tools and converters at Formatswap.com.

Leave a Reply

Your email address will not be published. Required fields are marked *