Problem
So, I have recently started using Ubuntu and I often face the problem of typing the same commands again and again. We know that 80% of the commands that we use everyday are only 4 or 5 of them. It sometimes becomes frustrating as well as time-consuming. Well, this is not how I want to make use of my precious time. What should I do then?
Solution
Well, I came across the concept of aliasing today which made me realise that this is the exact solution to my problem. You must be wondering that what does aliasing mean? Let me try to tell what I understand by it. Aliasing simply means giving a nickname to something.
Suppose, a friend of yours has a name "Ramakrishna". You'd rather call him R.K. instead of addressing him by his name everyday. So, R.K. is his nickname. Similarly, we can give nicknames to our daily use commands. Thus, this is called aliasing.
In order to make aliases, you can use the following steps:
-
Firstly, go to your terminal and open the
.bashrc
file ongedit
so that you can edit your file.gedit ~/.bashrc
-
Once, the
gedit
text editor is opened, create the alias and save the file.alias <nickname> ='The command you want to give a nickname to'
alias ll='ls -l' //Command to show all the files in your system
Kill the current terminal and reopen it. Then execute ll
Voila!! Now you can view all the files in detail. This is one such example of aliasing.
One specific use case of aliasing is when there's a file that's nested deeply within multiple directories. In such scenario, writing the whole path to access it would be a waste of time.
It can also be used when we are regularly pulling and pushing our code to remote repositories such as on GitHub. Suppose, we can give an alias to git add as:
alias ga='git add .'
Limitations
We know that every thing has its own benefits and limitations. This goes for aliasing as well.
It is very important for us to know when is it of use and when it's not.
Let's take an example where you have created some aliases on your own system and you are so dependent on them, that if given another system, you wouldn't be able to execute the actual commands. So depending entirely on anything is wrong.
Also, aliasing should be used only when you need to repeatedly use some command. Creating an alias for a command that only needs to be used once does not make any sense. Suppose, you can execute a direct command in one minute, whereas creating an alias and executing it takes more time that to when that command only needs to be run once.
Thus, I would like to conclude by saying that aliasing can be greatly useful to us provided we keep in mind its use cases.
Top comments (2)
Short and Crisp....Good Content 👏🏻👏🏻
Thank youu so much! I'll try to write more such blogs