Alias is my friend

A note on leveraging alias to create shortcuts for the most frequently used commands

Table of contents

No heading

No headings in the article.

This is the first post in the series of #50WeeksOfWriting where I am going to write about tips, new learnings, and experiences of being a developer.

As developers, the terminal is our friend. I still remember using the MS DOS terminal to run md and cd commands to make directories and change the current directory. In my day job, we use Kubernetes(K8s) to spawn multiple data processing jobs and Cloud Object Storage(COS) to store the inputs and results. So I keep running kubectl commands to interact with the K8s cluster and minio commands to query the COS. There are some commands that we use so frequently that there should be a better way than entering that long command every time or using the up arrow to go till the last time we used it.

One day, a friend of mine saw me typing these long commands again and again in the terminal and told me about alias. Essentially we can use a shortened string and add it as an alias to the longer command. Then every time, we use the shortened string in the command line, it will act as of the long command is used.

Here is a step-by-step explanation of how we can add a new alias.

  1. Open the bash/ZSH config file on your terminal

     # If you use bash
     vi ~/.bashrc # you
    
     # If you use ZSH
     vi ~/.zshrc
    
  2. Scroll down to the list of aliases

  3. Add your new shortcut(s)

     alias kpods="kubectl get pods"
     alias klogs="kubectl get logs -f"
     alias k="kubectl"
    
  4. Reload the bash/ ZSH config

     source  ~/.zshrc
    
  5. Type alias to list all the aliases and verify that your newly added alias is in the list

  6. Use your alias and save time :smile: