Creating Aliases on Linux

One thing that always trips me up is the command to clear the terminal window. On Windows this command is just cls but on Linux the command is clear. Muscle memory is hard to break sometimes. The solution is to setup an alias to map cls to clear. It's actually really easy to do. The approach I used is to create a .aliases file my home directory and then source that file into both the ZSH and Bash.

First, create the .aliases file in the editor of your choice. Here I'm using nano.

nano ~/.aliases

In this file define any aliases you want. The syntax for an alias is alias command=target. So for my example to map cls to clear would look like this.

alias cls=clear

The final step is to source the .alias file in the .zshrc, .bashrc or the config file for your terminal of choice.

source ~/.aliases

Relaunch the terminal and your good to go.

The best part about this approach is that if you end up using multiple shells, you can define you custom aliases once and the reuse it any shell you want. On top of that when you come up with new alias you want to create, you've got one place to make a change.