Linux上使用pushd的时候,遇到了奇怪的问题,当我在/root/test folder下创建了tmp1,tmp2,tmp3 三个文件夹
drwx-----T 5 root root 4096 2011-08-11 05:09 ./
drwx------ 8 root root 4096 2011-08-10 05:21 ../
drwxr-xr-x 2 root root 4096 2011-08-11 05:09 tmp1/
drwxr-xr-x 2 root root 4096 2011-08-10 05:09 tmp2/
drwxr-xr-x 2 root root 4096 2011-08-10 05:09 tmp3/
然后执行在test folder下执行pushd,如下:
root@computer:~/test# pushd ./tmp1
~/test/tmp1 ~/test ~/test
root@computer:~/test/tmp1# dirs -v
0 ~/test/tmp1
1 ~/test
2 ~/test
此时我们是在tmp1目录下,执行cd ..回到上一级目录,再进行dirs查询:
root@computer:~/test/tmp1# cd ..
root@computer:~/test# dirs -v
0 ~/test
1 ~/test
2 ~/test
root@computer:~/test#
诡异的一幕出现了,栈中原来的目录没有了,全部换成了~/test。至今不明白为什么会这样。
但是当我使用以下面的方式使用pushd的时候则没有此问题
root@computer:~/test/tmp1# dirs
~/test/tmp1
root@computer:~/test/tmp1# pushd .
~/test/tmp1 ~/test/tmp1
root@computer:~/test/tmp1# cd ..
root@computer:~/test# cd tmp2
root@computer:~/test/tmp2# pushd .
~/test/tmp2 ~/test/tmp2 ~/test/tmp1
root@computer:~/test/tmp2# cd ..
root@computer:~/test# dirs -v
0 ~/test
1 ~/test/tmp2
2 ~/test/tmp1
或者我们可以使用-n参数,如下:
root@computer:~/test# dirs
~/test
root@computer:~/test# pushd -n ./tmp1
~/test ./tmp1
root@computer:~/test# pushd -n ./tmp2
~/test ./tmp2 ./tmp1
root@computer:~/test# pushd -n ./tmp3
~/test ./tmp3 ./tmp2 ./tmp1
root@computer:~/test# dirs -v
0 ~/test
1 ./tmp3
2 ./tmp2
3 ./tmp1
在这里,-n参数只将其后的参数即目录压入到栈中,但是并不切换目录,当前目录始终是test目录。
分享到:
相关推荐
今天小编就为大家分享一篇关于linux shell之pushd、popd和dirs的使用讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
在Linux的多目录命令提示符中工作是一种痛苦的事情,在Linux命令提示中,可以用cd命令来改变当前目录。用pushd实现在不同目录间切换。文中介绍了利用cd和pushd切换目录的技巧有助于你节省时间和精力。
在Linux的多目录命令提示符中工作是一种痛苦的事情,但以下这些利用cd和pushd切换目录的技巧有助于你节省时间和精力。本文介绍了Linux操作系统中巧用CD和Pushd切换目录的方法。
PUSHD(directory/file-spec) 存储当前工作目录并将当前目录更改为字符串 directory-spec 中指定的目录。 要返回存储目录调用 POPD,请... PUSHD 和 POPD 这两个文件旨在模仿 UNIX/Linux 和 DOS 中具有相同名称的函数。
唯一的区别是:每次使用 pushd 时,您留下的目录都会保存在堆栈中。 要返回,只需键入 popd,它会将您带到堆栈顶部的目录。 要查看堆栈中的内容,请使用 dirs。 堆栈大小不受限制。 在 Matlab 命令行中键入“help ...
ubuntu ubuntu_编译时出现_bin_sh_1_pushd_ not found
pushd, 快速的多协议移动和网络推送通知服务 通用移动推送守护进程这就是一个可以向移动本地应用程序发送服务器端通知的服务器,你可以从一个入口点向任何支持的移动平台,网络应用程序或者HTTP服务器发送推送通知。...
pushd.mac如何使用应该在防火墙中打开端口2222(可选)和2223,我们将其用作tcp服务器和s2s网关独立删除“ etc_servers”部分或将其留空运行服务器:bin / pushd。(linux | mac) 运行客户端(例如telnet):telne
技巧 50:使用HISTTIMEFORMAT 在历史中显示TIMESTAMP 技巧 51:用Ctrl + R 搜索历史命令 技巧 52:四种不同的方法快速执行之前的命令 技巧 53:执行历史命令中的特定命令 技巧 54:执行以特定字开头的历史命令 技巧...
用法:pushd PATH将当前目录保存在堆栈上,并将目录更改为PATH。 :pushd不带任何参数,将目录更改为您的主目录。 :popd将目录更改为堆栈上的最新目录,然后将其从堆栈中删除。 :dirs列出堆栈中的目录,最近列出。安装...
Fast command-line navigation using pushd and popd 126 Counting number of lines, words, and characters in a file 128 Printing directory tree 129 Chapter 4: Texting and Driving 131 Introduction 132 ...
切换目录的方式有很多种,最常用的莫过于cd 命令了,这里介绍四个命令pushd,popd,dirs,cd -的使用方法
pushd、popd 和 dirs 实现了一个 unix 风格的目录栈。... 用法示例: > cd myDir myDir> pushd('anotherDir') anotherDir> %excute 命令在这里另一个目录> 目录目录另一个目录> popd myDir> % 回到你开始的地方
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
通常,这是ES2015或> 0.5%, last 2 versions, Firefox ESR, not dead如果使用 > 0.5%, last 2 versions, Firefox ESR, not dead 。 请查看以获取更多信息。在Node.js中确保您已安装最新的LTS版本的Node.js。 此SDK...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装