Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I return to the previous working directory quickly in Bash?

Tags:

bash

shell

When I change into a directory with the cd command, I lose the previous working directory, unless I remember it in my memory. Is there some handy method to go back quickly?

Demo:

$ cd ~/some_path $ cd /another_path $ command_to_go_back_to_some_path 
like image 722
Ethan Zhang Avatar asked Apr 30 '12 10:04

Ethan Zhang


2 Answers

You can go back to the last dir with cd -

like image 108
Darragh Enright Avatar answered Nov 15 '22 17:11

Darragh Enright


You can also do this

$ pushd ~/some_path $ pushd /another_path $ popd  $ popd 
like image 45
pizza Avatar answered Nov 15 '22 16:11

pizza