pushd
Save and then change the current directory. With no arguments, pushd
exchanges the top two directories.
SYNTAX
pushd [dir | +N | -N] [-n]
KEY
+N Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
-N Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
-n Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
dir Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir'. cds to dir.
Related Linux Bash commands:
dirs - Display list of remembered directories
popd - Restore the previous value of the current directory saved by PUSHD
If your linux not have pushd command, and you OS is Redhat or Fedora Core, you can download it from here:
http://rpmfind.net/linux/rpm2html/search.php?query=perl-Sys-Pushd
上面是rpm包,在Redhat上直接双击安装即可,然后输入pushd看是否有这个命令。
pushd使用示例:
如果我希望在/usr/src和/etc/X11和/boot/grub之间切换,则可以在命令行下输入:
pushd /usr/src
pushd /etc/X11
pushd /boot/grub
然后输入dirs查看,事实上每次输入都会显示当前pushd堆栈中的内容。
可以看到显示三个路径:
/boot/grub /etc/X11 /usr/src
输入pushd,既可以在前两个路径之间相互切换。
如果想切换到最后一个(栈底)路径时 pushd +2即可。
其他详细参数看上面帮助。
