dirs
显示目录堆栈。
概要
1dirs [-clpv] [+N] [-N]
主要用途
-
显示目录堆栈。
-
清空目录堆栈。
选项
1-c 清空目录堆栈。
2-l 堆栈内以~开头的目录在显示时展开。
3-p 将目录堆栈内的每一个目录按行显示。
4-v 将目录堆栈内的每一个目录按行显示并在每行前加上堆栈内的位置编号。
参数
+N(可选):不带参数执行dirs
命令显示的列表中,左起的第N个目录将被显示。(从0开始计数)
-N(可选):不带参数执行dirs
命令显示的列表中,右起的第N个目录将被显示。(从0开始计数)
返回值
返回成功除非提供了非法选项或执行出现错误。
例子
1# 添加目录到堆栈。
2[[email protected] ~]$ dirs
3~
4[[email protected] ~]$ pushd -n ~/Desktop
5~ ~/Desktop
6[[email protected] ~]$ pushd -n ~/Pictures
7~ ~/Pictures ~/Desktop
8[[email protected] ~]$ pushd -n ~/bin
9~ ~/bin ~/Pictures ~/Desktop
10
11# 选项和参数的示例:
12[[email protected] ~]$ dirs -l
13/home/user2 /home/user2/bin /home/user2/Pictures /home/user2/Desktop
14[[email protected] ~]$ dirs -p
15~
16~/bin
17~/Pictures
18~/Desktop
19[[email protected] ~]$ dirs -v
20 0 ~
21 1 ~/bin
22 2 ~/Pictures
23 3 ~/Desktop
24[[email protected] ~]$ dirs +2
25~/Pictures
26[[email protected] ~]$ dirs -2
27~/bin
28[[email protected] ~]$ dirs -c
29[[email protected] ~]$ dirs
30~
注意
bash
的目录堆栈命令包括dirs popd pushd
。- 当前目录始终是目录堆栈的顶部。
- 该命令是bash内建命令,相关的帮助信息请查看
help
命令。
来源:https://github.com/jaywcjlove/linux-command