dirs command lists a stack of recently visited directories. You can push into the history with the
pushd command, and pop off the stack (going back one location) with the
dirs with the
cd command. The
cd command will change directory, but it won't remember your navigation history. You can use
pushd like a version of the
cd command that saves a history of where you've been.
Some common flags for
-c-- clear the stack
-l-- long format
-p-- one path per line
-v-- one path per line with indices
These examples assume a unix-like operating system like GNU/Linux or Mac.
This command will navigate to the
/var/ directory, pushing your last location onto the
$ pushd /var/
Display the stack:
Navigate back to the last visited directory by popping off the stack.
Regular format (home is represented with a tilde):
$ dirs /var ~/code/CSS/codeselfstudy_wiki
$ dirs -l /var /home/pv/code/CSS/codeselfstudy_wiki
$ dirs -v 0 /var 1 ~/code/CSS/codeselfstudy_wiki