DEV Community

Jason F
Jason F

Posted on

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?

Top comments (2)

Collapse
 
stephenwhitmore profile image
Stephen Whitmore

Aliases are fun! I use quite a few as well - some more practical than others. One of my favorites is replacing sudo with please so you have please pkill chromedriver and please dnf update.

Instead of closing the terminal and reopening it you can run source ~/.bashrc and your changes will be loaded into your current terminal session.

Collapse
 
juniordevforlife profile image
Jason F

Thanks for sharing Steve! I may have to steal your please command.