How to use aliases to customize ubuntu commands

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.

How to use aliases to customize ubuntu commands

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

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

Syntax for creating an alias:

How to use aliases to customize ubuntu commands

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

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.

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:

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:

  • You cannot use an already existing command as an alias name. If you do this, your alias will not work, instead, the default ubuntu command will be executed.
  • The alias name cannot contain any spaces. If the new alias you want to set up contains two or more words, you can use the ‘-’ character to separate those words.

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

  • ← How to Open and Edit Files and Folders in Ubuntu Desktop as an Administrator
  • 8 Ways to Customize your Ubuntu 18.04 Desktop →

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Linux users often need to use one command over and over again. Typing or copying the same command again and again reduces your productivity and distracts you from what you are actually doing.

You can save yourself some time by creating aliases for your most used commands. Aliases are like custom shortcuts used to represent a command (or set of commands) executed with or without custom options. Chances are you are already using aliases on your Linux system.

List Currently Defined Aliases in Linux

You can see a list of defined aliases on your profile by simply executing alias command.

Here you can see the default aliases defined for your user in Ubuntu 18.04.

List Aliases in Linux

As you can see, executing.

Is equivalent to running:

You can create an alias with a single character that will be equivalent to a command of your choice.

How to Create Aliases in Linux

Creating aliases is relatively easy and quick process. You can create two types of aliasestemporary ones and permanent. We will review both types.

Creating Temporary Aliases

What you need to do is type the word alias then use the name you wish to use to execute a command followed by “=” sign and quote the command you wish to alias.

The syntax is as follows:

Here is an actual example:

You can then use “wr” shortcut to go to the webroot directory. The problem with that alias is that it will only be available for your current terminal session.

If you open new terminal session, the alias will no longer be available. If you wish to save your aliases across sessions you will need a permanent alias.

Creating Permanent Aliases

To keep aliases between sessions, you can save them in your user’s shell configuration profile file. This can be:

The syntax you should use is practically the same as creating a temporary alias. The only difference comes from the fact that you will be saving it in a file this time. So for example, in bash, you can open .bashrc file with your favorite editor like this:

Find a place in the file, where you want to keep the aliases. For example, you can add them in the end of the file. For organizations purposes you can leave a comment before your aliases something like this:

Save the file. The file will be automatically loaded in your next session. If you want to use the newly defined alias in the current session, issue the following command:

To remove an alias added via the command line can be unaliased using unalias command.


This was a short example on how to create your own alias and execute frequently used commands without having to type each command again and again. Now you can think about the commands you use the most and create shortcuts for them in your shell.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

How to use aliases to customize ubuntu commands

Using the command line seems rugged and unpleasant, but Linux has a way to ease things up and help you get things done with the command line by allowing you to use aliases to customize how you type commands.

Setting up Aliases

Aliases are a way for you to customize the commands by giving them aliases (nicknames). You can use them to remember hard commands or make short names to long commands you just hate to type. To setup aliases, right-click and create an empty file in your home directory and name it “.bash_aliases”. Notice the period at the beginning of the name that will make the file hidden. Press “Ctrl+H” to show the hidden files.

How to use aliases to customize ubuntu commands

Aliases Syntax

Using your favorite text editor open the file you just created and start making your aliases. But there are few things you should keep in mind, the syntax should be:

Where “new_name” is the alias, and “old_command” is the command you want to change and is put between quotes. Example:

This will make typing “agi” the same as typing “sudo apt-get install”. This way if you have a dozen of packages to install, your task just got easier. Keep in mind that if you create an alias that looks the same as a command, then the command or alias will not work. Example:

The alias in the above example won’t work because there is already a command by the name “install”.

And remember that creating aliases from two words won’t work unless you connect them with a dash. Example:

alias apt install=’sudo apt-get install’

alias apt-install=’sudo apt-get install’

In the above example, the first alias is invalid as the alias consists of two separate words while the second alias is good to use because the two words are connected with a dash. And the last thing that you shouldn’t do is put any space at the starting of any line. So that’s everything about creating the aliases, but what aliases would you use? Keep reading!

What aliases to use

Now that you know how to setup aliases and create your own. Let’s see what aliases you can use to make the most out of it.

  • Manage packages

If you have to install and remove packages too often then you really are going to like this.

alias agr=’sudo apt-get remove’

alias agu=’sudo apt-get update’

alias acs=’apt-cache search’

The aliases above are made of the first letters of each word in the command. These are just examples of what you can use and you can use them, modify them or create your own.

  • Manage files and folders

These aliases will make the command line ask you for confirmation on deleting files or overwriting them (if there were duplicates) when copying or moving files as well as give you more information on what is being done. This can prevent you from accidentally overwriting your files or sending them to somewhere you shouldn’t send them to.

  • Navigating the system

Now navigating your files and folders can be no easier. Type the directory you want to go to and type dots to go up.

  • Other useful aliases

alias shutdown=’sudo shutdown –h now’ #requires root password, disable it by “sudo chmod u+s /sbin/shutdown”

alias restart=’sudo shutdown –r now’ #requires root password, disable it by “sudo chmod u+s /sbin/shutdown”

alias suspend=’sudo pm-suspend’

alias lock=’gnome-screensaver-command –lock’

alias mounted=’mount | column –t

Got any more tips or great aliases? Share them in the comments.