# MAN 手册原文:

       pushd [-n] [+n] [-n]
       pushd [-n] [dir]
              Adds  a  directory to the top of the directory stack, or rotates the stack, making the new top of the
              stack the current working directory.  With no  arguments,  exchanges  the  top  two  directories  and
              returns 0, unless the directory stack is empty.  Arguments, if supplied, have the following meanings:
              -n     Suppresses the normal change of directory when adding directories to the stack, so  that  only
                     the stack is manipulated.
              +n     Rotates the stack so that the nth directory (counting from the left of the list shown by dirs,
                     starting with zero) is at the top.
              -n     Rotates the stack so that the nth directory (counting from the right  of  the  list  shown  by
                     dirs, starting with zero) is at the top.
              dir    Adds dir to the directory stack at the top, making it the new current working directory.

              If  the  pushd  command is successful, a dirs is performed as well.  If the first form is used, pushd
              returns 0 unless the cd to dir fails.  With the second form, pushd returns  0  unless  the  directory
              stack  is  empty, a non-existent directory stack element is specified, or the directory change to the
              specified new current directory fails.
----------
# 概要:
pushd 把一个目录dir添加到目录堆栈顶部;或者交换堆栈顺序,是当前工作目录成为新的栈顶。

没有参数时,只是交换两个目录顺序,使得第二个目录成为栈顶,原栈顶目录下移,成功返回0;只有当目录堆栈为空返回非零值。

----------

命令 作用
dirs 显示目录栈的内容,即便目录栈为空,它也会显示当前工作目录。
pushd 把当前工作目录压栈,成为栈顶。
popd 将目录弹出目录栈

# 操作记录

1)没有把任何目录压入目录栈时,目录栈为空,此时的pushd, popd 命令都是无效的,会出错,只有 dirs 命令能够显示一个目录,但这个目录不在目录栈里面。
2)“pushd $PWD” 把当前工作目录压入栈里面,dirs 命令能够显示两个目录,第一个是栈顶,刚刚压入的目录;而 “popd” 也能够正确执行,是因为它能够弹出栈顶。执行第二次肯定出错。

----------

如果没有使用 pushd $PWD 命令,那么栈顶的目录是临时的,使用 popd 目录会弹出栈顶那个目录,使得当前工作目录切换到序号为1的目录,例如:

再例如:


------
# 指定弹出第 n 个目录条目
终于搞明白了 "pushd +5" 的意思:原来目录栈是一个循环结构,当把序号为5的栈蛇者为栈顶,那么其后面的序号就从0开始,到了栈底再从最前面的目录条目开始,直到遇到刚刚设立的那个栈顶。





pushd的更多相关文章

  1. 【转载】dirs、pushd、popd指令

    转载自:http://hi.baidu.com/linuxtrip/item/47a38c8eec00e98f4414cfb7 一.目录栈指令 目录栈是用户最近访问过的系统目录列表,并以堆栈的形式管理 ...

  2. [转]编译错误: /bin/sh: 1: pushd: not found的问题

    [转]编译错误: /bin/sh: 1: pushd: not found的问题 http://blog.csdn.net/ojinxi/article/details/12186839 ubuntu ...

  3. linux shell pushd popd dirs命令

    1.dirs 1)功能显示当前目录栈中的所有记录(不带参数的dirs命令显示当前目录栈中的记录) 2)语法(1)格式:dirs  [-clpv]  [+n]  [-n](2)选项-c    删除目录栈 ...

  4. linux环境ubuntu: pushd: not found

    编译错误: /bin/sh: 1: pushd: not found的问题 http://www.cnblogs.com/wansui/p/4230869.html 查看原因:进入/bin目录,查看s ...

  5. 命令行的目录栈(pushd指令与popd指令)

    在命令行下经常需要切换目录,通常的做法是手打目录名,而如果有时候我们需要临时离开一个目录去操作什么,过会再回来,重新打一次目录想必是很麻烦的,这时候就可以用目录栈了,直接pushd 目录,然后就放心的 ...

  6. Linux命令:pushd

    语法 pushd [-n] [+N | -N | dir] 更改新目录并(或)压栈,或者把栈里的某个目录推到栈顶. 说明 pushd dir # 切换到目标目录dir,并将dir压栈. pushd # ...

  7. Linux 下 pushd,popd,cd- 用法

    一,为何要使用这几个命令? 可能大家会有疑问,为何要使用这几个命令,   难道用cd不就可以切换目录了吗?   没错,使用cd就可以切换到需要访问的目录,   但是有时会是一个路径很长,层次很多的目录 ...

  8. pushd和popd

    [原文地址]   其实,很早就知道pushd和popd在linux中可以用来方便地在多个目录之间切换.那时比较浮躁,感觉切换目录没必要这么复杂.在实际中,发现通过使用pushd和popd能够极大地提高 ...

  9. cmd下PUSHD和POPD命令使用说明

    PUSHD命令保存当前目录以供 POPD 命令使用,然后改到指定的目录. PUSHD [path | ..] path 指定要成为当前目录的目录. 如果命令扩展被启用,除了一般驱动器号和路径,PUSH ...

随机推荐

  1. 推荐使用C++ 11

    如果你的代码工作正常并且表现良好,你可能会想知道为什么还要使用C++ 11.当然了,使用用最新的技术感觉很好,但是事实上它是否值得呢? 在我看来,答案毫无疑问是肯定的.我在下面给出了9个理由,它们分为 ...

  2. c#调用word com组件 替换书签套打

    安装office2007,添加com引用Microsoft Word12.0 Object Library和Microsoft Office12.0 Object Library using Syst ...

  3. 用PHP实现Windows域验证

    系统集成中,可能会有这种需求 Windows 域验证本质上是LDAP验证 但在网上居然找不到详细的技术文档,可见不受待见之极.

  4. Maven初步搭建 (一)

    什么是maven? 也许很多人开始的时候跟我一样,在看了很多工程之后都不知道这个鸟东西到底是用来干嘛用的!:-D 一个东西之所以会出现是有其原因的,譬如Linus大神写git. Maven项目对象模型 ...

  5. SQL Server Insert时开启显式事务

    如果没法避免一条一条的写入,那么在处理前显示开启一个事务 begin tran  在处理完成后 commit 这样也要比不开显示事务会快很多! while i < 10000begin inse ...

  6. [Windows Phone] APP上架,遇到错误2001的解决方案。(Error:2001)

    [Windows Phone] APP上架,遇到错误2001的解决方案.(Error:2001) 问题情景 最近在开始玩Windows Phone的开发,开发的过程中虽然有点小挫折,但是参考网络许多前 ...

  7. SilverLight MD5加密

    效果体验:http://keleyi.com/tool/md5.htm 嵌入页面的代码: <div style="width:400px;height:230px"> ...

  8. c#多线程生产者消费者(手稿)

    屋舍简陋,隔壁的娃娃哭了一晚,心中无恶意纯中性的想,有病就赶紧带孩子去看医生吧,能哭这么久估计孩子真的不舒服.

  9. 一些js小题(一)

    一些js小题,掌握这些对于一些常见的面试.笔试题应该很有帮助: var a=10; function aa(){ alert(a); } function bb(){ aa(); } bb();//1 ...

  10. vh属性-- 一个永远垂直居中的弹出框

    下面的demo,无论浏览器大小如何改变,滚动条是否滚动,弹出框永远水平垂直居中 <html> <head> <title></title> </h ...