Be Lazy: Use Bash Aliases

juniordevforlife

Jason F

Posted on September 17, 2020

Be Lazy: Use Bash Aliases

Bash Aliases

If you're anything like me, you find it tedious to open up your terminal and navigate to your project by typing in a long, absolute path, or by repeatedly using cd and ls to figure out where you're at and where you need to go. At home I keep all of my projects in a folder, befittingly named, projects.

Alt Text

Navigating to my projects folder isn't too bad, it's only a couple of directories in. However, I'm lazy, so let's do this the lazy way.

If you're following along, your first and biggest task will be to find your .bashrc file. For me, I am using Pop OS! 19.10 and it was located under the Home directory. I did have to enable the show hidden files option to see it though.

Alt Text

If you want to use your CLI to find it, you may have to go to your home directory and use something like ls -la | more

If you're having trouble finding it, a quick search in your favorite search engine of something like "where is .bashrc on Ubuntu 18.04" should work, just be sure to replace Ubuntu 18.04 with the OS that you're using. If you're using Windows and you've installed Git Bash, you'll have to do a search on how to find the .bashrc or add aliases to Git Bash. Also, you should make sure that you're using bash. Some operating systems use Z shell, or other shells. In my terminal, I can run echo $0 and it returns bash.

Alt Text

Now that you've (hopefully) found your .bashrc file, open it up with your favorite text editor. Here's mine:

Alt Text

As you can see, I've already created a few aliases. Today I'll create one to take me to my projects directory. I bet you can tell how to do this just from looking at the screenshot. If not, take a look at the gif below for that "ohhhhhh, that's how he did it" moment.

Alt Text

Testing Out The New Alias

...And now for the moment you've all been waiting for:

Alt Text

Please note that you'll need to close your terminal and reopen it for your changes to take effect.

Thoughts?

I'm a pretty average Linux user, however, I love learning cool techniques like this. What are your thoughts?

💖 💪 🙅 🚩
juniordevforlife
Jason F

Posted on September 17, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Be Lazy: Use Bash Aliases
codenewbie Be Lazy: Use Bash Aliases

September 17, 2020

Preparation plan for placement interviews
codenewbie Preparation plan for placement interviews

September 16, 2020