Making an alias for a specific command you do a lot, but for which a direct command doesn’t already exist, is incredibly useful and can save you a lot of time. This article will discuss how to make an alias in Ubuntu.
This should work in most versions of Ubuntu and probably Debian as well.
How To Make An Alias In Ubuntu
It is quite simple to make an alias in Ubuntu. Just follow these 3 steps.
Step 1: cd Into Your Home Directory
Open up a terminal, and go to your home directory. Most easily, just open a terminal and type
Step 2: Create .bash_aliases file
Then, use a text editor and open a file (possibly also creating the file) called .bash_aliases. The dot is important in the file name. You can use any text editor, but I use vim, so will demonstrate with vim.
Step 3: Create your alias in the .bash_aliases file
Then, to actually create the alias, you paste a line like the following.
For example, I have an alias for connecting to a VPS (virtual private server) using ssh. The command is relatively easy for me to remember, but it is tedious to have it type it over and over. So, I prefer to use an alias. The command I want to use is similar to
ssh [email protected]
To avoid having to type that over and over, I make an alias inside of .bash_aliases like the following:
alias myvps='ssh [email protected]'
The above alias will do the command
ssh [email protected], but having the alias allows me to just type
myvps into a terminal to run the command.
Once you have created your alias inside of .bash_aliases file, just save the file. You will probably then need to close all your terminals, and then open a new terminal. The alias then should be available to use in your terminal. For example, you could then type
myvps, and it would do the same thing as the ssh command mentioned above.
To add more than 1 alias, just make a new line for each alias, starting each new alias like was shown in the first example. So, for example for 3 aliases, it would look like the following.
You can name an alias whatever you want. Just use my examples as a basis.
Did you like this article? Do you have anything to add? Let’s discuss it in the comments below.