What is a fast command line way to switch between multiple directories for system administration? I mean, I can use pushd . and popd to toggle, but what if I want to store multiples and cycle through them, rather than permanently popping them off the bottom of the stack?
What is a fast command line way to switch between multiple directories for system administration?
bash;shell script;administration
Use pushd and then the special names for the directories in your directory stack: ~1, ~2, etc.Example:tmp $ dirs -v 0  /tmp 1  /tmp/scripts 2  /tmp/photos 3  /tmp/music 4  /tmp/picturestmp $ cd ~3music $ dirs -v 0  /tmp/music 1  /tmp/scripts 2  /tmp/photos 3  /tmp/music 4  /tmp/picturesmusic $ cd ~2photos $ cd ~4pictures $ cd ~3music $ cd ~1scripts $ The most effective way to use pushd in this way is to load up your directory list, then add one more directory to be your current directory, and then you can jump between the static numbers without affecting the position of the directories in your stack.It's also worth noting that cd - will take you to the last directory you were in.  So will cd ~-.The advantage of ~- over just - is that - is specific to cd, whereas ~- is expanded by your shell the same way that ~1, ~2, etc. are.  This comes in handy when copying a file between very long directory paths; e.g.:cd /very/long/path/to/some/directory/cd /another/long/path/to/where/the/source/file/is/cp myfile ~-The above is equivalent to:cp /another/long/path/to/where/the/source/file/is/myfile /very/long/path/to/some/directory/