I use "cd -" to jump back and forth between two directories.
Is there a command that will rotate between three directories?
There are commands (builtins) to maintain a stack of directories: pushd
and popd
.
man builtins
to get info on pushd
, popd
, and dirs
. Set up convenient aliases to navigate. e.g. after 2 pushes, pushd +1
will rotate through the 3 directories.
pushd
and popd
can be used here, however unlike the former poster: see also this howto once you have populated the $DIRSTACK
with directories you can also use dirs
and cd ~1
to jump to directories in $DIRSTACK
directly!
First add the second and third directories to the directory stack (your working directory is already in the stack).
pushd second/directory/path
pushd third/directory/path
Then rotate through your directories with the following command:
pushd +1
pushd/popd and $DIRSTACK solutions proposed in other answers are the "canonical" way.
Another option would be to use screen
command. You open your directories in different sreens and switch between next/previous using shortcuts - Ctrl-a n
for next and Ctrl-a p
for previous. Or using Ctrl-a anyNumber
to go to a specific screen. Or using Ctrl-a doublequote
to display and visually select which screen you want.
Check all possible window navigation shortcuts.
Try using 'z' link. It remember which directories you have been to and you can jump around with short commands and abbreviated directory names.
like said before, but with just a little more words:
for bash, basically: instead of using cd use pushd
to change directorys, so they are saved (meaning stacked)
pushd /home; pushd /var; pushd /log
To see the stack use dirs
and for easier navigation (to get the numbers of the "stack-entries" use:
dirs -v
Output:
me@myhost:/home$ dirs -v
0 /home
1 /var
2 /tmp
Now utilize these numbers with cd
and ~
like:
cd ~1
But now these numbers are rearranged now and position "0" will change, so just pushd
the directory to the top position twice (or use a dummy on position 0) like:
me@myhost:/home$ dirs -v
0 /home
1 /home
2 /var
3 /tmp
now 1..3 will keep there position I read this somewhere but do not know anymore, so sorry for not giving credit
(to release the current directory from stack/deleting it from the "dirs"-history use popd
)
.bashrc
file. If you add a full path you can use simple commands to jump between the directories.