# 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. 怎样实现Web控件文本框Reset的功能

    在ASP.NET开发过程序,在数据插入之后,文本框TextBox控件需要Reset.如果只有一两个文件框也许没有什么问题,如果网页上有很多文本框,你就会有点问题了.再加上某一情形,一些文本框是有默认值 ...

  2. 推荐使用C++ 11

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

  3. idea使用maven搭建springmvc

    最近学着搭建springmvc,写此博客记录一下 idea版本:2016.3.1maven: apache-maven-3.3.9tomcat:apache-tomcat-8.5.8 1.New Pr ...

  4. [PHP] 实现路由映射到指定控制器

    自定义路由的功能,指定到pathinfo的url上,再次升级之前的脚本 SimpleLoader.php <?php class SimpleLoader{ public static func ...

  5. C语言回滚(二)--循环打印

    //1.用循环打印 /* FFEFEDFEDCFEDCBFEDCBA */ #include <stdio.h> #include<stdlib.h> int main(){ ...

  6. urllib库初体验以及中文编码问题的探讨

    提出问题:如何简单抓取一个网页的源码 解决方法:利用urllib库,抓取一个网页的源代码 ------------------------------------------------------- ...

  7. 小白初学Ioc、DI、Castle Windsor依赖注入,大神勿入(不适)

    过了几天,我又来了.上一篇中有博友提到要分享下属于我们abp初学者的历程,今天抽出点时间写写吧.起初,我是直接去看阳光铭睿的博客,看了一遍下来,感觉好多东西没接触过,接着我又去下了github 里面下 ...

  8. 初识你---------Swift【下篇】

    Swift中的结构体 Swift的结构体对比OC来说,可以添加初始化方法.可以遵守代理协议等,同时:Swift的Bool类型的变量也是一个结构体,所以只能选择true和false. Swift中声明结 ...

  9. rabbitmq+ keepalived+haproxy高可用集群详细命令

    公司要用rabbitmq研究了两周,特把 rabbitmq 高可用的研究成果备下 后续会更新封装的类库 安装erlang wget http://www.gelou.me/yum/erlang-18. ...

  10. emberjs初学记要

    code { margin: 0; padding: 0; white-space: pre; border: none; background: transparent; } code, pre t ...