Ever wanted to go up a few directories when using the bash terminal? You probably had to do something like this:
cd .. (enter)
cd .. (enter)
cd .. (enter)

…until the end of time.

Worry not, for gone are those days. I was just browsing through some stackoverflow questions and ran into these extremely useful bashrc functions.

Now, all you have to do to go up N directories is type in up N, hit enter, and like magic, you’re up those many directories.

Here’s an example

Let’s say I’m here:

This is where I am initially.
This is where I am initially.

I want to go up 3 directories. Normally, this would involve typing in  cd .. (enter) three times. Now, all I have to do is type up 3 and I am there, like so:

Up 3
Up 3

Now, say I want to go back up 2 directories. All I have to do is type back 2, and I’m there.

Back 2
Back 2

So, how do you install these neat little commands? Here’s a step by step guide:

  1. Open up your terminal with  Ctrl + Alt + T.
  2. If you’re not already there, go to your home directory with  cd (enter).
  3. Load up your .bashrc file in your favourite text editor. For me, this was  gvim .bashrc.
  4. Add these functions to your .bashrc file, save, and quit.
Functions added to bashrc
Functions added to bashrc

5. Go back to your home directory and source your bashrc file like so:  source .bashrc

6. You’re done! Enjoy your new bash commands. 🙂

 

If you like these nifty little commands, please leave a comment below.