Everything You Need To Know About Linux Alias
In Linux, an alias is a way to define a new name for a command or set of commands. It allows you to use a shorter, easier to remember name for a command or to run a series of commands with a single name.
Aliases are useful for making it easier and faster to run frequently used commands, or for running complex commands that you don't want to type out every time. They can also be helpful for simplifying tasks that require running multiple commands in a specific order.
How To Configure Alias In Ubuntu?
To configure an alias in Ubuntu (or any other Linux distribution), you can use the "alias" command in your terminal. The general syntax for creating an alias is as follows:
alias alias_name='command'
To make the alias available every time you open the terminal, you can add it to your shell's configuration file. The configuration file for the default bash shell in Ubuntu is located at "~/.bashrc". To edit this file, you can use a text editor like nano or vim, or you can use the "echo" command to append the alias to the end of the file.
echo "alias update='apt-get update'" >> ~/.bashrc
Or Simply open your .bashrc
vi ~/.bashrc
and add your aliases there
What Are My Favorite Aliases? That I use it daily
As a programmer, we are inherently lazy and efficient. These are the type of Aliases that I use daily and you should too.
SSH into Servers
For each server I use, I have a Linux alias map to it. Eg:
Suppose I am working on a project "XYZ" and it's hosted on AWS(ip:1.1.1.1). My alias will look as
alias xyz_prod= "ssh -i key.pem [email protected]"
Do not forget to restart your terminal after adding alias
Next time I have login into the server. I just type
xyz_prod
That's it I am in
Quick Add, Commit Push
If I have to release a hot patch to a Git Repo. I just do
acp "<my commit message>"
The changes are added, committed and push to the Repository. This how my alias looks like
acp(){
git add .;
git commit -m "$1";
git push;
}
Always, use A PR this is just for hotfixes
Quick Navigation
This saves me a lot of time. I have mapped my most visited aliases to their name.
Eg: I have a folder that contains my projects. I can easily access this directory easily by just typing
projects
Here is how my alias looks like
alias projects="cd /mnt/c/projects"
Always remember to write the absolute path
Pro Tip: I have added cd /mnt/c/projects
at the bottom of my .basrhrc
so everytime I open my terminal I am in that folder. How cool is that 😎
Aliases For my favorite commands
There are some tools I use to improve my workflow and I have aliases mapped to them.
Eg: If you are a react developer and you need to serve your build locally.
I have a python http server mapped to serve
alias serve="python3 -m http.server 8080"
So I navigate to the folder and just type serve
and it starts an https server.
Another use case
Sometimes you want to share your project hosted at your localhost with your colleague, Manager or Client for this I use NGRok To forward my local port to the internet.
You guessed it right there is an alias map to that too.
Changing Inbuilt tool with more Efficient Ones
This is my favorite so far. You can upgrade your experience and not remember new stuff. Isn't it every programmer's dream?
This is how your top
commands look like

This is how my top
command looks like.

Yes, that is very cool. And you know what It's a GUI. You can interact with it using your mouse.
How do I do it? I used the tool BpyTOP. The problem is the name is fu**ing confusing. So I have an alias for it.
alias top="bpytop"
and it's as simple as that.
Conclusion
These are just my favorite ones I have a lot more aliases. But the point is not to give you my aliases but to enable you to identify your problem and solve it. Because at the end of the day.
Languages are just tools and We Programmers are just Problem Solvers.
Happy Coding 🎈