Understanding an alias in .bashrc

Noob
2 min readDec 15, 2020

There have been cases where I have had to write the same command again and again. Every time I open my workstation or start a repository, these commands seem to be so simple to write and execute but it is the repetition that seems tedious constantly. Well this article is not about .bashrc but about how to make your life a little easier using a very simple but a powerful concept called alias.

What is an alias?

An alias is nothing but a name given to a person/thing. Well in our case a command. Let’s look at an example to understanding how it actually works.

We are going to write an alias which will change the current directory by you using a simple word. So Let’s Start!!

Open your ~/.bashrc file and paste the following line.

alias enterwork='cd /Users/noob/Documents/work/repos/config';

Does this seem too simple. Well it is! Now to make this alias work, you will have to reload the .bashrc in your current shell.

Type the following command.

source ~/.bashrc

Now you can see the magic in action. write “enterwork” in your terminal and voila!

Terminal

You can use this for any command you like or even a set of commands. For example the following line changes the directory and executes a shell script named “run-server.sh”.

alias startwork='cd /Users/noob/Documents/work/repos/config; bash /Users/noob/Documents/work/repos/config/run-server.sh'

Note : If you’re using Oh My ZSH, then instead of using .bashrc, use .zshrc. To generalize it, use the config file which is executed on creation of a new shell session.

Now that you got an idea of how an alias works, go and have some fun with it.

--

--