2

I'm running CentOS 7, but hoping there is a general Linux way of doing this.

So you can cd back and forth between the previous and current directory with this:

cd -

Is there I way can cd back multiple directories? So I keep going back previous directories instead of just the last one?

Does Linux or bash track your navigation history at all?

Jakuje
  • 20,974
  • 7
  • 51
  • 70
user1028270
  • 1,024
  • 1
  • 15
  • 31
  • you could use bash history by pressing `Ctrl+r`, typing `cd` and repeated `Ctrl+r` to get location you want.. or add `"\e[A": history-search-backward` to `~/.inputrc` and then you could type `cd` followed by repeated `up` arrow to get location you want – Sundeep Jun 04 '16 at 15:15
  • See also http://unix.stackexchange.com/a/269272/117549 – Jeff Schaller Jun 04 '16 at 16:50
  • If the Linux did that, you would have a real bad memory leak. Linux is a kernel it must not do these things. It must only make it possible for processes to do it. (it also does not do the back button in the web-browser). bash is the file browser, so it will do it. – ctrl-alt-delor Jun 04 '16 at 21:09

1 Answers1

3

Yes and No.

If you use normal cd, it remembers only one previous location (in variable $OLDPWD), which is accessible using the mentioned cd -.

But you can go around using pushd path and popd, which keeps stack of previous locations.

Jakuje
  • 20,974
  • 7
  • 51
  • 70
  • neat so I guess I could alias `cd` to `pushd` and `cd -` to `popd`. Would that screw anything up? – user1028270 Jun 04 '16 at 15:13
  • First try that what does it do and what is in the manual page (in `man bash`). I would not use that for all the `cd`, but it is an option if you need it (you need to know it before you need it :)) – Jakuje Jun 04 '16 at 15:16