# 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. AEAI ESB V3.5.4开源发布,应用集成平台

    AEAI ESB 应用集成平台为数通畅联的核心产品,本着分享传递的理念,数通畅联将ESB管理控制台项目开源,目的在于满足客户与伙伴的OEM需求,以及为广大IT爱好者的集成工具提供多一种选择,多一种便利 ...

  2. C#中Guid类型值如何判断不是初始值!

    示例: public Guid _CurrentApplayInfoID { get; set; } 如何判断不是初始值"00000000-0000-0000-0000-0000000000 ...

  3. MySQL的字符集

    MySQL的字符集支持(Character Set Support)有两个方面:字符集(Character set)和排序方式(Collation). 字符(Character)是指人类语言中最小的表 ...

  4. js限制input输入

    1.取消按钮按下时的虚线框,在input里添加属性值 hideFocus 或者 HideFocus=true <input type="submit" value=" ...

  5. UVA 10090 - Marbles 拓展欧几里得

    I have some (say, n) marbles (small glass balls) and I am going to buy some boxes to store them. The ...

  6. Echarts图表控件使用总结1(Line,Bar)

    问题篇(详解):http://www.cnblogs.com/hanyinglong/p/4708337.html 1.前言 a.在系统开发过程中可能会使用到图表控件,一个好的图标控件可以使我们的网站 ...

  7. Smartforms常见问题

    分类: 1.使用SFSY-FORMPAGES显示总页数的时候,如果页数大于9,将会在前10页显示成星号* 解决: 有时候这样做完之后,星号*是没有了,但是字体会有颠倒或者重叠的现象. 如果出了这个问题 ...

  8. 原创:SAP LVC ALV编辑小技巧

    前两天有个打印需求变更,需要在ALV显示列表中添加两个字段,可编辑,而我自己用的是函数:REUSE_ALV_GRID_DISPLAY_LVC 因为之前做可编辑基本都是固定套路,定义类,画屏幕.... ...

  9. Docker: 解决Docker无法在电信网络中访问外网

    在电信网络中,Docker在build和run时会无法访问外网,原因是docker的默认dns地址是8.8.8.8,由于众所周知的原因,我们需要改写这个地址,方法如下: 修改/etc/sysconfi ...

  10. IOS 杂笔-10(Base64 加密)

    base64加密是可逆的,因此并不是很安全,在一些注重安全的地方很少用到,但是在普通传输中可以使用. 切忌,base64加密是不安全的. // // ViewController.m // CX-Ba ...