First things first. You need to decide which text editor you want to use for this tutorial. In Ubuntu, gedit is the default text editor and that’s what I prefer, so I will be using that. In Linux Mint, the default text editor will probably be either pluma or xed depending on which version you are running. Just enter one of those names in a terminal and it will open a blank text file if it is installed. If it’s not installed, it will tell you the command to install it. You can use whatever editor you want, you’ll just have to replace the word gedit with the name of your text editor in the commands below if you use something else.
Open a terminal and run the following command. This will open the file in the text editor you specify. In Ubuntu, this file already exists, so you will be adding things to the bottom of the file while being careful not to overwrite anything that’s already in there. In Linux Mint, this file does not exist by default, so this command will create the file and open it up with nothing in it. Mint users can start adding their custom stuff directly to the top of the file.
If your file is not blank, scroll down to the bottom and make a separator comment to remind you of where your commands begin. Any line that starts with a # will be commented out. It’s basically just a human readable note that the system will ignore.
# Custom Commands
Ok. Let’s get down to it. Any time you add an alias (custom command), you have to save the file and update it. So we are going to dumb this down a bit and make it real easy. Copy and paste this into your file.
# Edit ~/.bashrc alias rc='gedit ~/.bashrc' # Update ~/.bashrc alias uprc='source ~/.bashrc'
Now save the file and close it. Run this command to update the file.
From now on, you can type rc to open this file for editing. Then, after you save the file and close it, you can type uprc to update it.
This is where the real fun begins. Now you can start adding other aliases. You can run a super long command or launch complex scripts with just a single word.
In my Secure Shell (SSH) & Secure Copy tutorial, we learned how to create a secure password-less login to a remote computer. If we make an alias for that command, it becomes even simpler.
# Connect to HP Mini through SSH. alias mini='ssh blackmini@192.168.0.34'
Now I can just type the word mini in a terminal and I’ll instantly be connected to my HP Mini Notebook. Is that not freakin’ awesome? Here’s another example…
I have a directory in my home folder called MyScripts. By adding the alias below, I can change to that directory just by typing ms and I’ll instantly be taken there.
# Change directory to ~/MyScripts. alias ms='cd ~/MyScripts'
I’ll leave you with one last example before I go. Ever get tired of typing sudo apt-get install? Then this one is for you. From now on you can just type getapp followed by the application name.
# Install an application. alias getapp='sudo apt-get install'
Try to make sure you don’t create an alias that is already a command as that would potentially cause issues, but other than that, the sky is the limit!