介绍:
cd(英文全拼:change directory)用于切换当前工作目录
可以说是最常见的命令了
语法:
cd [dirName]
指定的目录可以是绝对路劲,也可以是相对路劲
实例:
1.回到用户家目录
直接用cd目录省略,就可以切换到当前使用者的家目录
同 cd ~ 和cd – (~ 、-- 也表示为 home 目录)
[root@localhost /]# cd
[root@localhost ~]# cd ~
[root@localhost ~]#
或者使用绝对路径cd /home/user_name/ 不过root用户除外,它的家目录就是/root
2.切换到根目录
[root@localhost ~]# cd /
[root@localhost /]#
3.切换到上次所在目录 -
[root@localhost /]# cd /usr/local/nginx/
[root@localhost nginx]# pwd
/usr/local/nginx
[root@localhost nginx]# cd -
/
[root@localhost /]#
4.切换到上一级目录
一个点表示当前目录,两个点表示上一级目录,…/…就是返回上两级目录
[root@localhost /]# cd /usr/local/nginx/
[root@localhost nginx]# cd ..
[root@localhost local]# cd ../..
[root@localhost /]#