Shell

How to Create Aliases for Customizing Commands in Ubuntu

How to Create Aliases for Customizing Commands in Ubuntu

Ubuntu allows you to customize your long and rugged bash commands by using short and pleasant aliases as a replacement. When you are working on the command line, you can just use an alias instead of the entire command you want to avoid typing. The alias will work exactly in the same way as the command it has been created against.

In this tutorial, you will learn how to create and use an alias against a command in Ubuntu. We will make use of a simple example to demonstrate this process for you. We are running the steps and commands described in this article on a Ubuntu 18 system.

Example: Setting up an alias for the - sudo apt-get install - command

If you do a lot of installations on your system and wish to avoid using the entire sudo apt-get install command, you can create a short alias for it using the following method:

Through the file manager, open the .bashrc file located in your home folder. This file is usually a hidden file so you will need to use the Ctrl+H control to view all the hidden files located in the folder. You can use your favorite text editor through the command line or UI to edit this file. We are using the default graphical text editor to open and edit this file.

Move to the end of the file and paste the following line:

alias agi="sudo apt-get install"

Here “agi” is the new alias we are setting up.

Syntax for creating an alias:

alias [aliasName]='old_command'

You can also add other aliases to customize your apt-get commands by adding the following lines to this file:

alias agr="sudo apt-get remove"
alias agu="sudo apt-get update"
alias acs="apt-cache search"

Save the file by clicking the Save button located at the top right corner.

Open the Terminal through Ubuntu Dash or by pressing Ctrl+Alt+T

Run the following command in order to start using the new bashrc file.

$ source ~/.bashrc

The new .bashrc file is installed every time you log out and then log in. The above command enables you to use the changes without restarting your system.

The alias has been set-up; you can now run the following command in order to install a new package to your system:

$ agi [package name]

Example:

$ agi nautilus-admin

Instead of

$ sudo apt-get install nautilus-admin

You can see how in the above image I was able to install Nautilus by using the new command alias that I set up in this example.

Points to consider

While creating an alias please note the following points:

Now you can get rid of the dry and rugged bash commands and use your own customized aliases to run the frequently used operations.

Gry Vulkan for Linux Users
Vulkan for Linux Users
With each new generation of graphics cards, we see game developers push the limits of graphical fidelity and come one step closer to photorealism. But...
Gry OpenTTD vs Simutrans
OpenTTD vs Simutrans
Creating your own transport simulation can be fun, relaxing and extremely enticing. That's why you need to make sure that you try out as many games as...
Gry OpenTTD Tutorial
OpenTTD Tutorial
OpenTTD is one of the most popular business simulation games out there. In this game, you need to create a wonderful transportation business. However,...