How to create aliases to customize commands in Debian

s2 0

Debian allows you to customize your long and robust bash commands by using short and pleasant aliases as replacements. When working at the command line, you can just use an alias instead of the entire command that you don’t want to type. The alias works the same as the command for which it was created.

This tutorial will show you how to create and use an alias for a command in Debian. We will demonstrate this process using a simple example. We are performing the steps and commands described in this article on a Debian 10 Buster system.

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

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

1. Open the .bashrc file in your home folder using the file manager. This file is usually a hidden file, so you will need to use the Ctrl + H controls to see all of the hidden files in the folder. You can use your favorite text editor from the command line or user interface to edit this file. We’ll use the standard graphical text editor, gedit, to open and edit this file.

2. Go to the bottom of the file and add the following line:

Alias ​​agi = ‘sudo apt-get install’

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

The 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’

and also,

Alias ​​acs = ‘apt-cache-search’

3. Save the file by clicking the Save button in the upper right corner.

4. Open the terminal using the Application Launcher search as follows:

Debian Terminal

The Application Launcher can be accessed with the Super / Windows key.

5. Run the following command to use the new bashrc file.

$ source ~ / .bashrc

Source bashrc

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

6. The alias is set up; You can now run the following command to install a new package on your system:

$ traded [package name]


$ agi nautilus-admin

Instead of

$ sudo apt-get install nautilus-admin

Using the Alias ​​Command

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

Points to consider:

Note the following points when creating an alias:

  • You cannot use an existing command as an alias. If you do this, your alias will not work, the standard Debian command will run instead.
  • The alias cannot contain any spaces. If the new alias you want to set up contains two or more words, you can separate those words with the “-” character.

Now you can get rid of the dry and sturdy Bash commands and use your own custom aliases to perform the commonly used operations.

How to create aliases to customize commands in Debian