免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1284 | 回复: 0
打印 上一主题 下一主题

Linux切换目录 pushd命令 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-16 17:38 |只看该作者 |倒序浏览
2009-09-02   追风
只要玩过linux的命令行,切换个目录那简直是小菜一碟,直接cd命令就搞定了,但是除了简单的cd命令,还有许多其他的命令,能够令你的操作更加方便快捷。
假设一种情况,一个文件A存放在了第十层目录ten中,经过千辛万苦好不容易进入了ten,结果一不小心敲入了一个cd命令,看着光标在根目录下闪烁,是不是很无奈呢?难道要再千辛万苦的敲一堆路径重新进到ten目录?
不必这么麻烦,输入“cd -”,看看是不是回到刚才的路径呢?
注:“cd -”能完成当前目录和之前所在的目录之间的切换
另外一个方便路径切换的命令就是pushd,可以完成多个不同路径之间的切换.
如果我希望在/usr和/etc/ssh和/etc/rc.d和当前路径之间切换,则可以在命令行下输入:
cxu@cxu-desktop:~$ pushd /usr
/usr ~
cxu@cxu-desktop:/usr$ pushd /etc/ssh
/etc/ssh /usr ~
cxu@cxu-desktop:/etc/ssh$ pushd /etc/rc.d
/etc/rc.d /etc/ssh /usr ~
pushd会自动把当前路径加入到可切换路径中。执行dirs,可以看到显示四个路径:
cxu@cxu-desktop:/etc/rc.d$ dirs
/etc/rc.d /etc/ssh /usr ~
输入pushd,既可以在前两个路径之间相互切换。
如果想切换到最后一个(栈底)路径时 pushd +2即可。
cxu@cxu-desktop:/etc/rc.d$ pushd
/etc/ssh /etc/rc.d /usr ~
cxu@cxu-desktop:/etc/ssh$ pushd
/etc/rc.d /etc/ssh /usr ~
cxu@cxu-desktop:/etc/rc.d$ pushd +2
/usr ~ /etc/rc.d /etc/ssh
cxu@cxu-desktop:/usr$
如果想清空这些路径,执行dirs -c即可。
cxu@cxu-desktop:/usr$ dirs -c
cxu@cxu-desktop:/usr$ dirs
/usr
cxu@cxu-desktop:/usr$
如果你需要从堆栈中删除一个目录,键入popd,然后是目录名称,再按回车键。
最后附上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
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103559/showart_2053962.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP