Skip to content

Commit 29484db

Browse files
authored
Update cd.md
本次修改增加了对切换到上一个工作目录的说明,以及新增的注意事项。
1 parent 03cad48 commit 29484db

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

command/cd.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,20 @@ dir(可选):指定要切换到的目录。
3939
cd # 进入用户主目录;
4040
cd / # 进入根目录
4141
cd ~ # 进入用户主目录;
42-
cd - # 显示并返回进入此目录之前所在的目录(也就是根目录);
4342
cd .. # 返回上级目录(若当前目录为“/“,则执行完后还在“/";".."为上级目录的意思);
4443
cd ../.. # 返回上两级目录;
4544
cd !$ # 把上个命令的参数作为cd参数使用。
4645
```
4746
47+
关于切换到上一个工作目录的说明
48+
49+
```shell
50+
cd -
51+
# 命令会首先显示要切换到的目标目录,然后再进入。
52+
cd ${OLDPWD}
53+
# 命令会直接切换到上一个工作目录。
54+
```
55+
4856
关于`CDPATH`
4957
5058
```shell
@@ -78,4 +86,6 @@ shopt -u cdable_vars
7886
7987
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
8088
89+
2. 建议您在编写脚本的过程中如有必要使用`cd`命令时,请增加必要的注释以用于提醒阅读者当前工作目录,以免出现诸如`找不到文件`这类问题的发生。
90+
8191
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

0 commit comments

Comments
 (0)