Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2224626
  • 博文数量: 533
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7046
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(533)

文章存档

2024年(2)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-07-14 22:34:54



Linux切换目录 pushd命令


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 on
ly the stack is manipulated.

dir Makes the current 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

阅读(4577) | 评论(0) | 转发(0) |
0

上一篇:iptables

下一篇:LINUX 下的VNC安装

给主人留下些什么吧!~~