cd命令来自于英文词组”change directory“的缩写,
其功能是用于更改当前所处的工作目录,路径可以是绝对路径,也可以是相对路径,
若省略不写则会跳转至当前使用者的家目录
1、功能说明
从当前工作目录切换到指定的工作目录。
2、语法格式
cd [选项] [目录]
3、选项解释
- 仅使用”-“选项时,当前目录将被切换到环境变量对应值的目录
~ 切换至当前用户目录
.. 切换至当前目录位置的上一级目录,若当前目录为“/“,则执行完后还在“/"
/ 跳转到跟目录
4、参考实例
cd /
[root@xiaonong nginx]
/etc/nginx
[root@xiaonong nginx]
[root@xiaonong /]
/
cd /etc
[root@ xiaonong]
/root
[root@ xiaonong]
[root@ xiaonong etc]
/etc
cd 或 cd ~
[root@xiaonong etc]
[root@xiaonong ~]
/root
cd .. 或 cd ../
[root@xiaonong nginx]
/etc/nginx
[root@xiaonong nginx]
[root@xiaonong etc]
/etc
cd -
[root@xiaonong nginx]
/etc/nginx
[root@xiaonong nginx]
/etc
cd ../../
[root@xiaonong nginx]
/etc/nginx
[root@xiaonong nginx]
[root@xiaonong /]
/
cd !$
[root@xiaonong /]
[root@xiaonong nginx]
/etc/nginx
[root@xiaonong nginx]
[root@xiaonong etc]
cd ..
[root@xiaonong /]
/
5、补充说明
相对路径是从当前目录或指定的目录开始的,eg: usr/
绝对路径是从"/"根开始的路径,eg: /usr
切换当前用户上一次所在目录:cd -
切换当前用户的家目录时:cd ~
切换当前目录上一级目录所在的路径时:cd ..