Bash Aliases: Take Them With You

Written by atulthosar | Published 2023/05/09
Tech Story Tags: bash | linux | productivity | command-line | devops | shell-script | tutorial | programming

TLDRSoftware associates create aliases and write them in the `~/.bashrc` file. aliases are available whenever they logged in to their machine. It's very difficult to copy/paste the aliases every time s/he logs in to the another machine. Create your aliases, categorize and put them in different files.via the TL;DR App

*nix Aliases

We all know how aliases on the *nix system help to create short commands for the long ones. E.g. kga can stand for kubectl get all or gl for git log --name-status --decorate. Software associates create such aliases and write them in the ~/.bashrc file. So aliases are available whenever they logged in to their machine.

The Challenge

However, associates also need to log in to other *nix machines for various purposes. Say a developer needs to log in to the SV system for live troubleshooting of an issue. Or a DevOps Engineer requires to log in to various cloud VMs. One has become very used to his/her alias s/he has created. It's very difficult to copy/paste the aliases every time s/he logs in to the another machine.

The Solution

Here is one way to address this challenge. Create your aliases, categorize and put them in different files. Say General Aliases, Git Aliases, Docker Aliases etc. Then create a setaliases.sh file. Download it on the machine you have logged in.

wget https://raw.githubusercontent.com/simplyatul/bin/master/setaliases.sh

and then source it

source setaliases.sh

That's it. All your aliases are set.

If you are frequently logging in to a particular machine, then just copy the above source command in the ~/.bashrc file.

Also published here.


Written by atulthosar | Software Engineer by profession. Also enjoys playing Lawn Tennis.
Published by HackerNoon on 2023/05/09