DEV Community

Kai Timmer
Kai Timmer

Posted on

The single most timesaving bash shortcut

It is a bit of embarrassing but I spent 10 years in my field without knowing the

cd -,git checkout/merge -

shortcut.

The -references the last folder/branch you accessed. So this is a thing:

$ pwd
/Users/kait/Downloads

$ cd test
$ pwd        
/Users/kait/Downloads/test

$ cd -
$ pwd
/Users/kait/Downloads

Probably the biggest revelation I ever had once a colleague of mine told me.

Top comments (3)

Collapse
 
awwsmm profile image
Andrew (he/him)

If you like that, check out popd and pushd

Collapse
 
ofcourseican profile image
Kai Timmer

That one I actually knew before :) But yeah, especially in scripts pushd and popd are awesome.

Collapse
 
bradtaniguchi profile image
Brad

Ah yes, the - shortcut, the "back button" of bash! 😄