Linux命令行技巧——使用目录栈进行导航
Title: Linux命令行技巧——使用目录栈进行导航
Author: Charles Shih
Create: 2017-08-31 17:03:28
- 目录栈导航
- 基本命令
- 目录栈结构
- pushd命令
- popd命令
- 相关文章
目录栈导航
基本命令
dirs
列出当前的目录栈;
pushd
改变目录并将“原当前目录”入栈;
popd
将栈顶的目录出栈并改变当前目录;
备注:dirs
命令的-v
参数用于列出目录及其序号,-l
参数用于列出目录全名,而-c
参数用于清空目录栈。
目录栈结构
[cheshi@cheshi-laptop2 ~]$ dirs -l -v0 /home/cheshi1 /home/cheshi/temp/0/52 /home/cheshi/temp/0/43 /home/cheshi/temp/0/34 /home/cheshi/temp/0/25 /home/cheshi/temp/0/1
[cheshi@cheshi-laptop2 ~]$
备注:栈中序号为”0”的是当前目录,序号越小目录越靠近栈顶。
pushd命令
pushd
与cd
命令的异同:
- 相同点:它们都可以改变当前目录,即栈中序号为”0”的目录。
- 不同点:cd
不改变目录栈的结构(除序号”0”对应的目录改变),但pushd
会使原来栈中所有目录的序号加”1”(即发生入栈)。
连续使用不带参数的pushd
命令:当前目录会在栈中序号为”0”和”1”的目录之间切换,效果类似于cd -
(但cd
命令只改变序号为”0”的目录)。
[cheshi@cheshi-laptop2 0]$ dirs -v0 ~/temp/01 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 0]$ cd -; dirs -v
/home/cheshi/temp/0/50 ~/temp/0/51 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 5]$ cd -; dirs -v
/home/cheshi/temp/00 ~/temp/01 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 0]$ pushd; dirs -v
~/temp/0/5 ~/temp/0 ~/temp/0/4 ~/temp/0/3 ~/temp/0/2 ~/temp/0/10 ~/temp/0/51 ~/temp/02 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 5]$ pushd; dirs -v
~/temp/0 ~/temp/0/5 ~/temp/0/4 ~/temp/0/3 ~/temp/0/2 ~/temp/0/10 ~/temp/01 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 0]$
pushd +N
可以用来“轮寻”堆栈,将当前序号为”N”的目录循环到栈顶(同时也切换到这个目录)。这个命令不改变栈中目录之间的次序关系,它是最常用的“目录栈”导航方式。
[cheshi@cheshi-laptop2 0]$ dirs -v0 ~/temp/01 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 0]$ pushd +4; dirs -v
~/temp/0/2 ~/temp/0/1 ~/temp/0 ~/temp/0/5 ~/temp/0/4 ~/temp/0/30 ~/temp/0/21 ~/temp/0/12 ~/temp/03 ~/temp/0/54 ~/temp/0/45 ~/temp/0/3
[cheshi@cheshi-laptop2 2]$
此外,pushd
也支持-N
操作,效果跟+N
差不多,只是方向相反,不再赘述。
popd命令
popd
正好与pushd
相反,使用不带参数的popd
将会使目录栈中序号为”0”的目录出栈,其他所有目录的序号减”1”,原序号为”1”的目录成为序号为”0”的当前目录。
[cheshi@cheshi-laptop2 0]$ dirs -v0 ~/temp/01 ~/temp/0/52 ~/temp/0/43 ~/temp/0/34 ~/temp/0/25 ~/temp/0/1
[cheshi@cheshi-laptop2 0]$ popd; dirs -v
~/temp/0/5 ~/temp/0/4 ~/temp/0/3 ~/temp/0/2 ~/temp/0/10 ~/temp/0/51 ~/temp/0/42 ~/temp/0/33 ~/temp/0/24 ~/temp/0/1
[cheshi@cheshi-laptop2 5]$
popd +N
命令用来将指定序号的目录出栈,并将其后的所有目录序号减”1”。但要注意的是,这个操作并不改变当前目录(除非你指定的是序号为”0”的目录)。
[cheshi@cheshi-laptop2 0]$ dirs -v0 ~/temp/01 ~/temp/0/32 ~/temp/0/23 ~/temp/0/14 ~/temp/05 ~/temp/0/56 ~/temp/0/4
[cheshi@cheshi-laptop2 0]$ popd +4; dirs -v
~/temp/0 ~/temp/0/3 ~/temp/0/2 ~/temp/0/1 ~/temp/0/5 ~/temp/0/40 ~/temp/01 ~/temp/0/32 ~/temp/0/23 ~/temp/0/14 ~/temp/0/55 ~/temp/0/4
[cheshi@cheshi-laptop2 0]$
此外,popd
同样也支持-N
操作,与+N
类似,只不过它是从栈底开始计数的,因此-0
为栈中最后一个目录,不再赘述。
相关文章
Linux 命令行工具使用小贴士及技巧(一)
Linux 命令行工具使用小贴士及技巧(二)
Linux命令行技巧——使用目录栈进行导航相关推荐
- Linux命令行技巧
Linux命令行技巧 命令 描述 • apropos whatis 显示和word相关的命令. 参见线程安全 • man -t man | ps2pdf - > man.pdf 生成一个PDF格 ...
- 十个有用的linux命令行技巧
我记得我第一次使用 Linux 的时候,我还习惯于 Windows 的图形界面,我真的很讨厌 Linux 终端.那时候我觉得命令难以记忆,不能正确使用它们.随着时间推移,我意识到了 Linux ...
- netflix linux_Netflix如何处理故障转移,Anaconda,Linux命令行技巧,Python日期时间库,GDPR,微服务等
netflix linux 上周,Amjith Ramanujam的页面浏览量超过12,000, 关于Netflix如何在7分钟内完成故障转移的文章是我们失控的热门. 您是否有关于您的组织如何确保最大 ...
- 实用的Linux命令行技巧
实用的Linux命令行技巧 1. 输出内容格式化 例如mount命令的输出结果看起来很费劲 请点击此处输入图片描述 可以使用column对其进行格式化 mount | column -t 请点击此处输 ...
- 你应该知道的 Linux 命令行技巧
2019独角兽企业重金招聘Python工程师标准>>> 这篇文章来源于Quroa的一个问答<What are some time-saving tips that every ...
- 计算机视觉研究人员必备的Linux命令行技巧
介绍 Jeroen Janssens在<命令行的数据科学>一书中对命令行优势进行了很好的分类: 命令行是灵活的:这个特性使它非常适合数据科学的探索性质.因为你想要及时得到结果. 命令行可以 ...
- linux指令诀窍大全,六个优雅的Linux命令行技巧
一些异常有效的敕令能让敕令行的生活更知足 应用 Linux 敕令工作可以获得很多乐趣,然则如不雅您应用一些敕令,它们可以削减您的工作或以有趣的方法显示信息时,您将获得更多的乐趣.在今天的文┞仿中,我们 ...
- 20个超高效的Linux命令与技巧
简介:这里有一些很有用的 Linux 命令,终端技巧和快捷方式,可以在使用Linux命令行时节省大量时间. 在本文中,我将向您演示一些专业的Linux命令技巧,这些技巧将使您节省大量时间,在某些情况下 ...
- linux 复制指定类型,用Linux命令行实现删除和复制指定类型的文件
(一)Linux 删除当前目录及子目录中所有某种类型的文件 方法1 : 此方法不能处理目录中带空格的那些. rm -rf `find . -name "*.example"` Li ...
最新文章
- Windows下Git的安装和基本使用、搭建Git服务器
- RPM YUM
- 计算机学科的三大科学形态,华中科技大学 计算机科学与技术方法论 3计算学科中的三个学科形态.ppt...
- python二级最后一题_python二级考试操作题2.pdf
- 【动态规划刷题笔记】线性dp:合唱队形(最长递增子序列的变体)
- python3.5中文手册chm_python3.5.2官方帮助文档 参考手册(CHM版)
- 《Android Framework-跨进程通信高级实战课》笔记
- 【DSP】win10安装CCS5.5教程及报错解决方法
- Nicolas Bourbaki 是何许人也,下一个中本聪?
- 面试常问:什么是红黑树?
- A记录、CNAME、MX记录、NS记录的区别和联系
- 纯字母域名批量注册的详细步骤
- OpenCV-细化算法(thinning algorithm)描绘出轮廓的中心线
- php函数名命名规范,PHP语言的命名规则
- 【moeCTF题解-0x04】Crypto
- PR CC 2018添加素材时出现绿色/紫色横线
- $.ajax的各个参数
- 《JavaScript 正则表达式迷你书》知识点小抄本
- kubesphere_KubeSphere
- 东京迪斯尼海洋乐园一日游