pushd和popd

The pushd command saves the current working directory in memory so it can be returned to at any time, optionally changing to a new directory.

The popd command returns to the path at the top of the directory stack. This directory stack is accessed by the command dirs

pushd

pushd [path | ..]

Arguments:

  •  path This optional command-line argument specifies the directory to make the current directory. If path is omitted, the path at the top of the directory stack is used, which has the effect of toggling between two directories

popd

popd

Examples

[test@dhcp-128-14 ~]$ dirs             //查看当前目录堆栈dirs中有哪些目录
~
[test@dhcp-128-14 ~]$ pushd ext/ ~/ext ~ [test@dhcp-128-14 ext]$ 切换到~/ext目录下
[test@dhcp-128-14 ext]$ dirs       //pushd命令不仅将ext目录压入目录堆栈,并且实现了切换到ext目录
~/ext ~
.....                     中间经过几次操作
[test@dhcp-128-14 ext1]$ dirs
~/ext/ext1/ext2 ~/ext/ext1 ~/ext ~

[test@dhcp-128-14 ext2]$ popd    //popd命令会将目录堆栈顶端的元素弹出,并且切换到次顶端所在的目录,popd命令是不用带参数的
~/ext/ext1 ~/ext ~
[test@dhcp-128-14 ext1]$     切换到~/ext/ext1目录下

[test@dhcp-128-14 ext1]$ dirs
~/ext/ext1 ~/ext ~

[yapei@dhcp-128-14 ext]$ dirs      //当目录堆栈dirs中只有两个目录时,不带任何参数的pushd能够实现在两个目录间切换
~/ext ~
[yapei@dhcp-128-14 ext]$ pwd
/home/yapei/ext
[yapei@dhcp-128-14 ext]$ pushd
~ ~/ext
[yapei@dhcp-128-14 ~]$      切换到~目录

[yapei@dhcp-128-14 ~]$ dirs
~ ~/ext
[yapei@dhcp-128-14 ~]$ pushd    
~/ext ~
[yapei@dhcp-128-14 ext]$    切换到~/ext目录

d[yapei@dhcp-128-14 ext]$ dirs
~/ext ~






 

 

posted @ 2015-06-23 15:50  yeddatian  阅读(409)  评论(0编辑  收藏  举报