5 Useful Time-Saving Bash Aliases

Defining bash aliases has always been a neat little trick for saving time on the command line. When learning about aliases, a few ideas may immediately jump out. There are also some you may not have thought about. I hope to uncover at least one of those. In this post, I’ll list 5 of my favorites. If you don’t know how to define bash aliases, I covered that here. Let’s get to it!

Number 1: Basic Git Aliases

When using git, it’s a given that you use a handful of commands over and over again. You can often shorten them to a few keystrokes without losing their semantic meaning. Here are a few examples:

git status can be aliased to gits

git log can be aliased to gitl

git commit --amend can be aliased to gitamend

and so on.. 

These are what I personally use, but do whatever makes sense to you.

Number 2: Navigation Aliases

The cd command is used in almost any situation. Why not make it a bit easier for yourself?

You can alias cd .. to a single character if you wish. That’s actually what I do, I alias it to a period.

#custom navigation aliases
alias . = "cd .."
alias .. = "cd ../.."
alias ... = "cd ../../.."
alias .... = "cd ../../../.."
alias ..... = "cd ../../../../.."

Now you can cd multiple directories at once typing only a few characters. Sure does come in handy!

Number 3: Open Your Project In One Command

Opening up a project and getting it to run is usually a multi-step process. Using the && operator, you can turn it into a single command and alias. Let’s break a basic process into 3 steps: navigation, opening up the folder in an editor, and running a build process.

alias my-project="cd ~/Desktop/project/path-to-your-project && code ./ && npm run start"

code ./ is how you’d open the current directory in vs code. This will vary between text editors, so be sure to look up what your equivalent is. In one single command, my project is up and running with the build started and the text editor clicking. I have at least 6-7 of these for specific projects.

Number 4: Check Your Local Weather

Pretty simple, it’s always nice to be able to do more in the command line. For this one, you need to type in the name of your city and it should be good to go.

alias myweather='curl "https://wttr.in/<your city here>"'

Not much more to it, this alias just lists a nice graph of your local weather.

Number 5: Quick System Upgrade

I’m sure a lot of you already have something like this, but I thought I’d mention it. Updating your system is a common process, and takes two commands. You can easily squish them together.

alias update="sudo apt update && sudo apt dist-upgrade"

Now, updating your system takes only a second of typing and is dead easy to remember.

Have any more?

I’d love to hear them! Feel free to share below your favorite time-saving bash alias

Comments