Bash alias's are a way to save some time when typing in the terminal. Simple enough. Luckily the syntax to create an alias for a command is just as easy!
alias <name>="<command>"
But, what are some things you might want to create an alias for? Well, here are some personal examples of mine, that I use quite frequently:
# Alias for pushd
alias pd="pushd"
# Alias for popd
alias p="popd"
I've fallen in love with pushd and popd. It's another way of moving around the terminal. It's like cd but different. When you push from one directory to another, you create a history that you can use to pop backwards, if you want to. So if you are in your ~/Downloads
directory and you pushd ~/Documents/projects/my-project
all you would have to do is type popd
to return to your Downloads directory. I've aliased them so they are a little shorter and easy to use all the time. I can pd my-project
and then to go back all I need to do is type p
and hit enter and --BAM!-- I'm in my projects folder again. It also creates a little synergy with my next group of alias's.
# Alias for lambda directory
alias lam="pushd ~/Documents/lambda"
# Alias for notes directory
alias note="pushd ~/Documents/notes"
# Alias for pets directory
alias pet="pushd ~/Documents/pets"
# Alias for experiments directory
alias exp="pushd ~/Documents/experiments"
# Alias for experiments directory
alias pack="pushd ~/Documents/packages"
# Alias for bin directory
alias bin="pushd ~/bin"
These are the directory's I spend the vast majority of my time working in. So, why not create small little key words that use to easily navigate to these folders from any location in my terminal? Again, using pushd so I have that history I can pop through.
# Alias for clearing terminal
alias x="clear"
# Alias for opening directory in VS Code
alias vs="code ."
Simple enough, make clearing your terminal and opening a project in VS Code that much easier. I can't tell you how many times I've typed code ,
only to open a file named ,
in VS Code, instead of opening my project...
And there we go!
Just a simple list of bash scripts I commonly use. Hopefully this inspires you to write some of your own alias and start saving time in your terminal today!
Top comments (2)
You are on a roll with all these posts lately Jimmy. Love seeing you share what you are learning. Keep it up. :)
Thank you so much! :) I'm getting the blog bug. So many things in my head that I want to get out now. Thanks for showing me this platform and inspiring me to finally start writing!!! <3