`
xfxlch
  • 浏览: 167117 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Hack 5. Manipulate Directory Stack

阅读更多
该组命令在日常应用中用到的应该不多。 这组命令可以用来把多个目录push到一个目录栈,然后可以pop出来。命令组合如下:
• dirs: Display the directory stack
• pushd: Push directory into the stack
• popd: Pop directory from the stack and cd to it

通常情况下执行这三个命令会有以下结果:

jack@Ubuntu:~$ dirs
~
jack@Ubuntu:~$ pushd
bash: pushd: 无其他目录
jack@Ubuntu:~$ popd
bash: popd: 目录栈为空



现在我们新建几个temp 目录:

jack@Ubuntu:~$ mkdir /tmp/dir1
jack@Ubuntu:~$ mkdir /tmp/dir2
jack@Ubuntu:~$ mkdir /tmp/dir3
jack@Ubuntu:~$ mkdir /tmp/dir4
jack@Ubuntu:~$ cd /tmp/dir1
jack@Ubuntu:/tmp/dir1$ pushd .
/tmp/dir1 /tmp/dir1
jack@Ubuntu:/tmp/dir1$ cd /tmp/dir2
jack@Ubuntu:/tmp/dir2$ pushd .
/tmp/dir2 /tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir2$ cd /tmp/dir3
jack@Ubuntu:/tmp/dir3$ pushd .
/tmp/dir3 /tmp/dir3 /tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir3$ cd /tmp/dir4
jack@Ubuntu:/tmp/dir4$ pushd .
/tmp/dir4 /tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir4$ dirs
/tmp/dir4 /tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1


【ps:打印出来的第一个目录/tmp/dir4并不是目录栈里的内容,而是当前目录。其后面的部分才是push到的目录栈的全部内容,很显然第一个push到栈里的是放在栈的最后面的,或者说是放在栈的最底部的】
下面我就把他pop出来:

jack@Ubuntu:/tmp/dir4$ popd
/tmp/dir4 /tmp/dir3 /tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir4$ pwd
/tmp/dir4
jack@Ubuntu:/tmp/dir4$ popd
/tmp/dir3 /tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir3$ pwd
/tmp/dir3
jack@Ubuntu:/tmp/dir3$ popd
/tmp/dir2 /tmp/dir1
jack@Ubuntu:/tmp/dir2$ pwd
/tmp/dir2
jack@Ubuntu:/tmp/dir2$ popd
/tmp/dir1
jack@Ubuntu:/tmp/dir1$ pwd
/tmp/dir1
jack@Ubuntu:/tmp/dir1$ popd
bash: popd: 目录栈为空


栈的后进先出在这里可以得到展示。

--EOF--
分享到:
评论

相关推荐

    Linux-101-Hacks

    Manipulate Directory Stack `dirs`命令可以显示当前的目录栈,而`pushd`和`popd`则可以对其进行操作。 ```bash dirs pushd /path/to/newdir popd ``` #### Hack 6. Automatically Correct Mistyped Directory ...

    Linux101 Hacks 2rd

    Manipulate Directory Stack** 除了`pushd`和`popd`外,还可以使用`dirs`命令查看目录栈的内容,使用`popd`+数字来弹出特定位置的目录,或使用`pushd`+数字来切换到目录栈中的某个位置。 **Hack 6. Automatically...

    程序分享如何实现实时滚动条效果类Mathematica的manipulate-manipulate.m

    程序分享如何实现实时滚动条效果类Mathematica的manipulate-manipulate.m 大家知道,在MATLAB中的滚动条控件是“非实时”的。所谓非实时,指的是用户在拖动滚动条时,滚动条的callback函数不会被触发,只有放开...

    Effective.Robotics.Programming.with.ROS.3rd.Ed.epub

    Design a robot and see how to make it map the environment, navigate autonomously, and manipulate objects in the environment using MoveIt! Add vision capabilities to the robot using OpenCV 3.0 Add 3D ...

    ArcGIS_Earth_x64_Setup_1_12.exe

    这里只是搬运官网的内容,让更多的人搜索的时候,能够找到下载的链接。请尽量在官网下载吧,官网下载... ArcGIS Earth is a free and easy-to-use tool to quickly fuse, manipulate, and collaborate with 3D data.

    Feature Manipulate Engine安装方法

    ##### 5. 启动许可服务器 - 使用LMtool工具启动许可服务器,并加载生成的许可文件。 - 打开LMtool,选择服务/许可文件选项,指定许可文件路径为`fmelicenseserver`,并保存服务设置。 ##### 6. 配置服务 - 在...

    counter hack reloaded

    see how you stack up. Where your policies, procedures, and technologies fall short, you can implement appropriate defenses to protect against the enemy. And that's what this book is all about: ...

    Manning Taming Text How to Find, Organize, and Manipulate It. Jan.2013.pdf

    1. 文档标题为《Manning Taming Text How to Find, Organize, and Manipulate It》(曼宁驯服文本:如何发现、组织和操作文本),这表明文件内容主要聚焦于文本处理技术,包括文本的检索、组织和操控方法。...

    Template class to manipulate bits of undefined type一个操作

    标题中的“Template class to manipulate bits of undefined type”指的是一个C++模板类,设计用于操作未定义类型(或者说不确定数据类型)的位。这样的类通常是为了实现位操作的通用性,允许开发者对任何类型的数据...

    python读取excel数据excel-manipulate-master.zip

    5. **高级功能**: - **合并单元格**:使用`openpyxl`的`cell`对象和`merge_cells()`方法。 - **格式化**:设置字体、颜色、边框、对齐方式等,`openpyxl`提供了丰富的样式控制。 - **图表**:`openpyxl`可以创建...

    tmux.2.Productive.Mouse-Free.Development.epub

    Your mouse is slowing you down. The time you spend context switching between your editor and your consoles eats away at your productivity....Chapter 5. Pair Programming with tmux Chapter 6. Workflows

    ques5.rar_The Power

    Write MATLAB code that ...(a) Manipulate image brightness. (b) Manipulate image contrast. (c) Perform image negative on binary and gray image. (d) Perform log transform. (e) Perform power-law transform

    spack-external:实验性的spack命令,用于操作外部软件包配置文件

    : 安装将以下配置添加到~/.spack/config.yaml : config : extensions : - /path/to/clone/of/this/repo用法$ spack external -husage: spack external [-h] SUBCOMMAND ...manipulate external package config ...

    ghsplit:自动分割大文件,以使它们不超过github的配额

    ghsplit 自动拆分和合并大文件,以使它们不超过Github的配额。 安装 pip install --user -e . ...Manipulate large files to avoid exceeding Github quotas positional arguments: {split,merge} the command; t

    bochs user manual 单html文件+pdf 英文原版

    8.11.5. Set up the host to masquerade the guest network accesses 8.12. Using the 'slirp' networking module 8.12.1. Advanced Slirp setup with config file 8.12.2. Access to guest services from the host ...

    Mastering.RethinkDB.1786461072.epub

    Master the powerful ReQL queries to manipulate your JSON data, Learn how to develop scalable, real-time web applications using RethinkDB and Node.js and deploy them for production, A detailed, step-by...

Global site tag (gtag.js) - Google Analytics