I personally use my shell (mac terminal) heavily to execute different commands on a daily basis. When I started my career, I got to know about this thing called “Shell Alias”.
Fast forward to few years, now whenever I set up any machine for development, I make sure to set up all my shell aliases first.
Trust me. This will make your life way easier! 🤘
What is a Shell Alias?
A Shell Alias is a shortcut to refer a command.
Why even bother using it?
Suppose you have to run few long commands on a daily basis.
Imagine trying to memorise and remember these long commands.
Don’t you wonder if there can be a way to avoid remembering these long commands?
Alias helps you do exactly that.
It lets you create a shortcut name for a command, file name, or any shell text.
In one word, it is:
How do you create one?
Create a .zshrc / .bashrc file (depending on the type of your shell) in the root directory.
Add aliases in this file.
Can also add/edit this file via Vim editor.“Legendary people use Vim!”
- literally said by everyone who uses Vim 😛
You may also find my other blog post on this useful -
Add alias in this format -
alias <SHORT_EASY_TO_REMEMBER_NAME> = <LONG_HARD_TO_REMEMBER_COMMAND>
Save and restart the shell.
Now, try running few commands. For example: Running local-db command will connect you to your local MySQL database.
This is how aliases will look like, inside the file -
Some useful commands
List all alias - alias
Display a specific alias original string - alias <ALIAS_NAME>
That’s it folks.
I will be back with another post shortly.
Goodbye till then. 👋