If you like keyboard shortcuts like me. You’re going to love aliases
.
If you don’t know about them. Don’t worry it’s super simple and you’ll learn it in no time.
What are aliases?
Think of them as abbreviations like LOL, and LMK, but for the terminal… IKR?
You create aliases for commands that you use frequently or that are too long to type. i.e eg. kubectl get services,deployments,pods
Pss. 🤫 What if I tell you, you're already using an alias?
Well, when you type ll
on the terminal it gets converted to ls -lh
that shows you a list of files, their size, permission, etc as opposed to the normal ls
command which only lists file names.
Run man ls
to learn more about -lh
flags.
# ll is short for -> ls -lh
total 208
-rw-r--r-- 1 anurag admin 1.5K Jun 5 09:10 favicon.svg
-rw-r--r-- 1 anurag admin 40K Jun 18 12:28 index.html
drwxr-xr-x 7 anurag admin 224B Jun 5 09:25 src
-rw-r--r-- 1 anurag admin 132B Jun 5 09:18 tailwind.config.js
-rw-r--r-- 1 anurag admin 470B Jun 18 12:33 tsconfig.json
-rw-r--r-- 1 anurag admin 138B Jun 5 15:17 vite.config.ts
Create Permanent aliases
Let’s create a custom alias gpom
which is an abbreviation for git pull origin master
.
This might look like a contrived example but the concept remains the same.
💡 Use abbreviations that you can recall easily. That’s the whole point.
For eg in this case I have used the first letter of every word from.
__
Edit ~/.zshrc
or ~/.bashrc
(Open it in VIM, VSCode, or any of your favorite editors)
💡 Create this file if it’s not present already.
Navigate to the bottom of the file and add this line.
alias gpom="git pull origin master"
Save the file and restart the terminal.
That’s it 🎉 Now when you run the command gpom
it will get converted to git pull origin master
View all aliases
If you want to view all the aliases. Run alias
in the terminal.
That’s pretty much it. Learn more about them here.
A short story about why I started using aliases.
I have two remote servers that I connect to via SSH. I host my side projects on them and tinker around with some DevOps stuff.
This is a demo ssh
command to connect to these servers.
# Connect to Server 1
ssh -i ~/.ssh/my-super-secret-key.pem piedPiper@11.208.234.196
# Connect to Server 2
ssh -i ~/.ssh/my-super-secret-key.pem piedPiper@18.201.294.191
Now whenever I want to connect to them, either I could type these, reverse search (Ctrl + R) to find the correct IP, or yes you guessed it, create easy-to-remember aliases.
So I have created two aliases prod-1
and prod-2
to connect to the remote servers.
A few days ago I realized that not a of people are using them so I tweeted about it and now I'm writing this blog. I hope you found it useful.
These are some of the aliases that I frequently use.
# npm and node
nrb='npm run build'
nrd='npm run dev'
nrs='npm run start'
# k8s and docker and others
k=kubectl
kga='kubectl get services,deployments,pods'
kgd='kubectl get deployments'
kge='kubectl get endpoints'
kgp='kubectl get pods'
kgr='kubectl get rs'
kgs='kubectl get services'
d=docker
dc=docker-compose
dcb='docker-compose build'
dcu='docker-compose up'
dcd='docker-compose down'
mqb=minikube
tf=terraform
wg=wrangler
That's pretty much it. Thank you so much for reading 🙌
I’m active on Twitter @abhagsain and on Linkedin Let’s connect :)