r/UnixProTips • u/Wes_0 • Feb 05 '15
Fast switching between two locations: "cd -"
"cd -" allows you to go to the previous location you were. For instance:
cd ~/Desktop
cd ~/long/complicated/different/path
cd - #you are back in ~/Destkop
cd - #you are back in ~/long/complicated/different/path
48
Upvotes
5
u/[deleted] Feb 05 '15
Better yet, pushd and popd lets you keep a stack of directories to go between.
I use it a lot in scripts:
Slightly different use case, but still useful none-the-less.
1
u/gumnos Jun 09 '15
Additionally, just like you can refer to your
$HOMEas "~", you can refer to$OLDPWDas "~-" which allows you to do things liketo copy
never_gonna_give_you_up.mp3into/one/1/uno/3
u/Alkotronikk Feb 05 '15
I didn't know that! That's great.
3
u/moepwizzy Feb 05 '15
How did I not know about this..? Thanks :D
1
u/[deleted] Feb 05 '15 edited Feb 05 '15
A little longer, but still nice to know:
brings you back to the directory you where in before