Skip to main content

How to create aliases for your commands

Spend lesser time developing by writing shorter commands

Updated 2 min readMarkdown
How to create aliases for your commands

Imagine reducing the command below:

git fetch && git checkout develop

to a shorter version:

gfc develop

Every time you type a full command when you could have autocompleted, or click when you could have used a shortcut key, you're expending precious limited cognitive power. Keep learning shortcuts for repetitive actions.

In the above command, the command git fetch && git checkout is replaced with the alias gfc. This alias could be whatever you wish to term it but make sure to avoid using already defined keywords (e.g npm, cd, touch, git, etc).

To set up an alias on your system. The first thing you need to do is to locate or create the file, .zshrc or .bashrc (depending on the shell you are using) in your home directory (~).

Mac - "/Users/your-username/.zshrc" 

Linux - "/home/your-username/.zshrc"

Next, open the file with any editor of your choice, in this tutorial, I'll be making use of nano text editor.

To open the file, launch your terminal, type nano ~/.zshrc and press enter. Then go to the bottom of the file and add a few aliases with the following syntax:

alias alias_name='command to be replaced'

Screenshot 2021-09-28 at 01.46.23.png

Done adding these new exciting aliases?馃槂 You can exit the nano editor by pressing ctrl + x , then press Y to save changes and then press the enter key.

Screenshot 2021-09-28 at 01.53.21.png

Restart your terminal and try out these new aliases 馃.

Happy aliasing!

Nice hacks, thanks for sharing

1

I'm glad you found it useful

Definitely trying this out. Thanks jefe

1

Alright, man. Thanks

Nice one, Lawrecks.

What about the alias command for Windows users?

;)

1

Lol. I Will update the post on it soon. Thanks