How to create aliases for customizing commands in Ubuntu

Ubuntu allows you to customize your long and strong bash commands, using short and nice aliases as a replacement. When you work on the command line, you can simply use an alias instead of the entire command that you want to avoid typing. An alias will work just like the team against which it was created.

In this guide, you will learn how to create and use an alias for a command in Ubuntu. We will use a simple example to demonstrate this process for you. We follow the steps and commands described in this article on Ubuntu 18.

Example: setting an alias for a command – sudo apt-get install –

If you make many installations on your system and want to avoid using the whole sudo apt-get install Command, you can create a short alias for it using the following method:

Open the file manager .bashrc the file is in your home folder. This file is usually hidden, so you need to use Ctrl + H control to view all hidden files located in the folder. You can use your favorite text editor through the command line or user interface to edit this file. We use the default image editor to open and edit this file.

Go to the end of the file and insert the following line:

alias agi='sudo apt-get install'

Here “agi” is the new alias we are customizing.

The syntax for creating an alias is:

alias [aliasName]=’old_command'

Alias ​​in .bashrc file

You can also add other aliases to customize the 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 in the upper right corner.

Open Terminal via Ubuntu Dash or by clicking Ctrl + Alt + T

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

$ source ~/.bashrc

A new .bashrc file is installed each time you log out and then log back in. The above command allows you to use the changes without rebooting the system.

An alias has been configured; Now you can run the following command to install the new package on your system:

$ agi [package name]

Example:

$ agi nautilus-admin

Instead

$ sudo apt-get install nautilus-admin

The newly created alis team in action

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

Questions to consider

When creating an alias, pay attention to the following points:

  • You cannot use an existing command as an alias. If you do this, your alias will not work, the default ubuntu command will be executed instead.
  • An alias cannot contain spaces. If the new nickname you want to configure contains two or more words, you can use the “-” symbol to separate these words.

Now you can get rid of dry and durable bash commands and use your own custom aliases to run commonly used operations.

How to create aliases to configure commands in Ubuntu

Sidebar