Author Topic: How to easily and quickly change directories in terminal  (Read 1097 times)

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
How to easily and quickly change directories in terminal
« on: March 25, 2017, 08:48:55 PM »
Okay, most of us spent quite a bit of time in a terminal window, right?
Now navigating between directories in terminal can be cumbersome sometimes.

For example you want to navigate to the "Terminator" directory,
Code: [Select]
~/Downloads/Videos/Movies/Action/Terminator/
You will have to enter,
Code: [Select]
cd Downloads/Videos/Movies/Action/Terminator/

I know you can use Tab-completion but even with it you'll agree there are plenty of key-presses involved here.

Okay, now assume you are in the "Terminator" directory and you want to go back to the "Videos" directory. You'll have to do,
Code: [Select]
cd "../ ../"

See, it's cumbersome! Here is the easiest and smartest method to change directories in terminal.

First we need to install a tiny application,
Code: [Select]
sudo apt-get install go2

After the installation has completed, in your terminal run,
Code: [Select]
go2; source $HOME/.bashrc

That's it! Now you can navigate to "Terminator" directory easily like this,
Code: [Select]
go2 Terminator

Or if you are in a hurry,
Code: [Select]
Go2 Term

And from "Terminator" directory going back to the "Videos" directory is just as easy,
Code: [Select]
go2 Videos

If in hurry,
Code: [Select]
go2 Vid

Now if you have two directories "Downloads" and "Documents" and you do,
Code: [Select]
go2 Do
go2 will prompt you to select one of them,
Code: [Select]
a: ~/Documents
b: ~/Downloads
If you want to select "Documents" you need to enter "a" and for selecting "Downloads" you enter "b". Simple!!!

For more info,
Code: [Select]
man go2

Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3894
    • View Profile
    • VSIDO Community
Re: How to easily and quickly change directories in terminal
« Reply #1 on: March 25, 2017, 09:08:41 PM »
Nice ... thanks for this one

Nothing like a How To to make a rainy day better!

Cheers!

only 114KB!!  HA! ...

 8)
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

VastOne

  •      v-ger
  • Posts: 3894
    • View Profile
    • VSIDO Community
Re: How to easily and quickly change directories in terminal
« Reply #2 on: March 25, 2017, 09:14:35 PM »
Any known reason why creating an alias

Code: [Select]
alias go='go2'
would be a bad idea?  Thinking in terms of scripts or any other need for 'go'
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
Re: How to easily and quickly change directories in terminal
« Reply #3 on: March 25, 2017, 09:16:23 PM »
It's so addictive you might stop using good old "cd"  8)

Cheers!!!
You Can't Always Git What You Want

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
Re: How to easily and quickly change directories in terminal
« Reply #4 on: March 25, 2017, 09:20:43 PM »
Any known reason why creating an alias

Code: [Select]
alias go='go2'
would be a bad idea?  Thinking in terms of scripts or any other need for 'go'

If someone is using Go, then it might not be a great idea  :-\

Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3894
    • View Profile
    • VSIDO Community
Re: How to easily and quickly change directories in terminal
« Reply #5 on: March 25, 2017, 09:23:04 PM »
Yeah.. pretty sure I will not have to worry there..

Thanks!
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
Re: How to easily and quickly change directories in terminal
« Reply #6 on: March 25, 2017, 09:25:18 PM »
Yeah.. pretty sure I will not have to worry there..

Thanks!

I don't use "Go" myself so the alias works fine for me too. It removes an extra key press  ;)

Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3894
    • View Profile
    • VSIDO Community
Re: How to easily and quickly change directories in terminal
« Reply #7 on: March 26, 2017, 12:17:31 AM »
What have I mucked up?

All I get when running go2 is

Code: [Select]
go2 already configured, skipping.
Google does not offer a thing.. hmmm
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
Re: How to easily and quickly change directories in terminal
« Reply #8 on: March 27, 2017, 05:52:54 PM »
Add following to your .bashrc,

Code: [Select]
GO2TMP=~/.go2/tmp
go2 () {
    /usr/lib/go2/go2.py $*;
    if [ -e $GO2TMP ]; then
cd "$(cat $GO2TMP)"
rm $GO2TMP > /dev/null
    fi
}

Save the file and run,

Code: [Select]
source $HOME/.bashrc

Try go2.

Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3894
    • View Profile
    • VSIDO Community
Re: How to easily and quickly change directories in terminal
« Reply #9 on: March 27, 2017, 05:53:59 PM »
I did get it to work after a dump of it and then a reinstall.. Not sure what it was but it is all good now!
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 512
    • View Profile
    • Looking at Linux through the Windows of Life
Re: How to easily and quickly change directories in terminal
« Reply #10 on: March 27, 2017, 05:55:11 PM »
That's great  :)

Cheers!!!
You Can't Always Git What You Want

a

  • Posts: 18
    • View Profile
Re: How to easily and quickly change directories in terminal
« Reply #11 on: April 28, 2017, 06:17:47 PM »
I like goto (https://github.com/ankitvad/goto.git)
Its just a bash script really that also puts an alias in your .bashrc
I like that i'ts easy to make shortcuts to dirs but even without it's seems to know all the dirs that are there. So if I type goto .scripts, it goes into my .scripts folder in my home folder without me first making a shortcut.