003_cd pushd popd三个命令的区别
一、
It depends. In zsh you can configure cd to push the old directory on the directory stack automatically, but it is not the default setting.
As far as I can tell zsh with default settings behaves very similar to bash:
cd somedir- change directory to
somedir - save the original directory in
OLDPWD - set
PWD="somedir" - replace top element of the directory stack (as shown by
dirs) withsomedir(the number of elements on the stack does not change).
- change directory to
cd -:- change directory to
$OLDPWD - swap values of
PWDandOLDPWD - modify the top element of the directory stack to reflect (the new)
PWD
- change directory to
pushd somedir:- change directory to
somedir - save original directory in
OLDPWD - set
PWD="somedir" - push
somedironto the directory stack (extending it by one element)
- change directory to
popd:- save original directory in
OLDPWD - remove first element of the directory stack
- change directory to the new top element of the directory stack
- set
PWDto the new top element of the directory stack
- save original directory in
Note: Whether the present working directory is considered an element of the directory stack differs between zsh and bash. I used bash as reference for the above lists.
In
bashthe present working directory is considered to be the top element of the directory stack. Theman 1 bashsays:pushd [-n] [dir][…] Adds
dirto the directory stack at the top, making it the new current working directory as if it had been supplied as the argument to thecdbuiltin. […]Printing
DIRSTACK(echo ${dirstack[@]}) confirms that the first element is identical to$PWD.In
zshthe present working directory is not part of the directory stack (but still shown withdirs).man 1 zshbuiltinssays:pushd [ -qsLP ] [ arg ][…] Change the current directory, and push the old current directory onto the directory stack. In the first form, change the current directory to arg. […]
Printing
dirstack(echo ${dirstack[@]}) and comparing it to the output ofdirsshould show that thePWDis not part of `dirstack.
In both shells dirs prints the present working directory as the first element. Also in both shells, the directory stack element with the index 1 refers to the directory which was current before the last pushd. That is because arrays in zsh are usually numbered from 1, while they are numbered from 0 in bash. So there is little practical difference
As said above, this behavior can be modified in zsh.
If you set the AUTO_PUSHD option in zsh (setopt autopushd) cd somedir behaves like pushd somedir, the previous directory is pushed onto the directory stack automatically. This is probably the case on your machine. You can run setopt to get a list of options that are not set the default way. See, whether autopushd appears in the list.
But this does not modify cd - to behave like popd. Instead it just pushes $PWD onto the directory stack, and changes directory to $OLDPWD. That means repeatedly calling cd - will actually grow the directory stack (($PWD $OLDPWD $PWD $OLDPWD $PWD …)). If it actually does behave exactly like popd on your system, I would suggest if cd is actually the builtin (whence -v cd); it is possible that its replaced with an alias or function.
As the directory stack will grow rather quickly with AUTO_PUSHD enabled, you can limit its size by setting the parameter DIRSTACKSIZE to the desired maximum size.
You can also prevent duplicates by setting the PUSHD_IGNORE_DUPS option.
For more options have a look at the manual.
参考:https://unix.stackexchange.com/questions/272965/pushd-popd-vs-cd-cd-in-bash-and-zsh
003_cd pushd popd三个命令的区别的更多相关文章
- [转]Linux中set,env和export这三个命令的区别
转自:http://www.2cto.com/os/201306/223758.html Linux中set,env和export这三个命令的区别 set命令显示当前shell的变量,包括当前用户 ...
- 命令stat anaconda-ks.cfg会显示出文件的三种时间状态(已加粗):Access、Modify、Change。这三种时间的区别将在下面的touch命令中详细详解:
7.stat命令 stat命令用于查看文件的具体存储信息和时间等信息,格式为"stat 文件名称". stat命令可以用于查看文件的存储信息和时间等信息,命令stat anacon ...
- pushd,popd,dirs,cd -让切换目录更方便
与linux cd命令相似,用pushd实现在不同目录间切换 在命令行模式下,当你工作在不同目录中,你将发现你有很多时间都浪费在重复输入上如果这些目录不在同一个根目录中,你不得不在转换时输入完整的路径 ...
- [转]Ubuntu中apt与apt-get命令的区别
转载于https://www.sysgeek.cn/apt-vs-apt-get/ Ubuntu 16.04 发布时,一个引人注目的新特性便是 apt 命令的引入.其实早在 2014 年,apt 命令 ...
- apt与apt-get命令的区别与解释
[apt与apt-get命令的区别与解释] Ubuntu 16.04 发布时,一个引人注目的新特性便是 apt 命令的引入.其实早在 2014 年,apt 命令就已经发布了第一个稳定版,只是直到 20 ...
- Linux快速目录间切换cd pushd popd
1. cd - 当前目录和之前所在的目录之间的切换 2. cd + Alt . 用上次命令的最后一个目录路径 要用上上次命令的最后一个目录,就Alt+.两次就可以了 3. push ...
- apt与apt-get命令的区别
apt 和 apt-get的区别 Debian 作为 Ubuntu.Linux Mint 和 elementary OS 等 Linux 操作系统的母板,其具有强健的「包管理」系统,它的每个组件和应用 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- Oracle学习笔记三 SQL命令
SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)
随机推荐
- dotTrace 每行执行时间和执行次数
如果代码中出现效率问题,使用dotTrace来跟踪分析代码的效率问题还是很方便的.使用dotTrace不但可以看到每一个方法被调用的次数和总时间,而且可以引入源代码,查看源代码中每一行执行的次数和时间 ...
- Codeforces 68D - Half-decay Tree
题意 有一颗高度为 \(h\) 的完全二叉树(即点数为 \(2^{h+1}-1\) ),有两种操作: add x y 给 \(x\) 点的权值加 \(y\) decay 一次衰变定义为选择一个叶子节点 ...
- Mouse Hunt CodeForces - 1027D(思维 找环)
Medicine faculty of Berland State University has just finished their admission campaign. As usual, a ...
- MySQL的COUNT()函数理解
MySQL的COUNT()函数理解 标签(空格分隔): MySQL5.7 COUNT()函数 探讨 写在前面的话 细心的朋友会在平时工作和学习中,可以看到MySQL的COUNT()函数有多种不同的参数 ...
- 【洛谷P2661】信息传递
题目大意:给定一个有 N 个点,N 条边且每个点的出度均为 1 的有向图,求该有向图的一个最小环. 题解:由于每个点的出度均为 1,可知可能的情况只有以下几种:一个环或多个环,一个环+一条链.因此,可 ...
- angularJs的继承
为什么要继承,本来是后端的概念,但是同样适用于前端开发.继承,无疑是将通用的东西抽取出来. 下面介绍的是angular的伪继承,就是说是通过继承scope这个变量来实现的.代码很简单,一行代码就可以. ...
- Easy2Boot-小清新教程
Author:KillerLegend Date:2014.8.14 From:http://www.cnblogs.com/killerlegend/p/3913614.html 之所以说是小清新, ...
- 设计模式之Mixin模式
介绍 mixin模式就是一些提供能够被一个或者一组子类简单继承功能的类,意在重用其功能.在面向对象的语言中,我们会通过接口继承的方式来实现功能的复用.但是在javascript中,我们没办法通过接口继 ...
- Linux命令(七)Linux用户管理和修改文件权限
1. 用户管理 1.1 创建用户/设置密码/删除用户 (-m很重要,自动添加用户家目录) 创建用户组dev, 给用户组dev新建xiaoqin用户,给新用户设置密码! 1.2 查看用户信息 1.3 设 ...
- 蓝桥杯 大臣的旅费_树的最长度_两次DFS
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> ...