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 ~






 

 

转载于:https://www.cnblogs.com/penny-jimmy/p/4595625.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值