# 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. Unity3D读取模型文件自动生成AnimatorController简单实例

    前几天接到一个任务,做一个导入.控制模型动画的工具类,没有太具体的要求,于是就自行思考实际需求,最终根据宣雨松老师的一篇博客,自己规范了一下写了一个工具类.相关工具代码及测试用例已上传至Github. ...

  2. Java数字图像处理基础 - 必读

    写了很多篇关于图像处理的文章,没有一篇介绍Java 2D的图像处理API,文章讨论和提及的 API都是基于JDK6的,首先来看Java中如何组织一个图像对象BufferedImage的,如图: 一个B ...

  3. jquery1.9+获取append后的动态元素

    jquery 1.9+放弃了live,说是用on代替了! 那么如果我们以前用live来获取jquery动态添加的元素,现在应该用on怎么写呢? 首先: <div id="one&quo ...

  4. BI之SSAS完整实战教程3 -- 创建第一个多维数据集

    上一篇我们已经完成了数据源的准备工作,现在我们就开始动手,创建第一个多维数据集(Cube). 文章提纲 使用多维数据集向导创建多维数据集 总结Cube设计器简介 维度细化 总结 一.使用向导创建多维数 ...

  5. 【jQuery基础学习】10 简单了解jQuery Mobile及jQuery各个级别版本的变化

    关于 jQuery Mobile jQuery Mobile是为了填补jQuery在移动设备应用上的一个新项目.它应用了HTML5和CSS3. 主要特性 基于jQuery构建. 采用与jQuery一致 ...

  6. ECMall如何支持SSL连接邮件服务器的配置

    首先,主要是ecmall使用的phpmailer版本太低,不支持加密连接. 然后,得对相应代码做一定调整. 1. 覆盖phpmailer 请从附件进行下载: http://files.cnblogs. ...

  7. Discuz!X3解读之类引入机制及目录结构

    实例: - /source/class/table/table_forum_faq.php - /source/class/model/model_forum_post.php - /source/p ...

  8. mysql 64 zip download

    open the url  ::  http://dev.mysql.com/downloads/file/?id=461109 and click the location "no tha ...

  9. 使用PowerQuery操作OData数据

             Excel是我们耳熟的办公软件.PowerQuery是一个允许连接多种数据源的Excel插件.它能从一个网页上智能查询数据.使用PowerQuery能合并数据集使用join,merg ...

  10. bootstrap 弹出框点击其他区域时弹出框不消失选项设置

    默认情况下,bootstrap 弹出框点击其他区域时,弹出框会自动关闭,在很多时候,我们可能会希望达到和原生弹出框一样的效果,避免不小心点击其他区域时弹框自动隐藏,尤其是对于一些复杂的表单,重复填写可 ...