Linux命令学习总结:cd命令

时间:2023-03-08 23:08:30
Linux命令学习总结:cd命令

命令简介:

该命令用来切换当前目录。cd 是change directory 的缩写

命令语法:

cd [-L|-P] [dir]

使用示例

1:切换到当前目录的上一级目录

   1: [root@DB-Server sysconfig]# pwd

   2: /etc/sysconfig

   3: [root@DB-Server sysconfig]# cd ..

   4: [root@DB-Server etc]# pwd

   5: /etc

2:切换到当前目录的上上两层目录

   1: [root@DB-Server etc]# cd sysconfig/ 

   2: [root@DB-Server sysconfig]# pwd 

   3: /etc/sysconfig 

   4: [root@DB-Server sysconfig]# cd ../.. 

   5: [root@DB-Server /]# pwd 

   6: /

3:切换到用户的宿主目录

   1: [root@DB-Server sysconfig]# pwd

   2: /etc/sysconfig

   3: [root@DB-Server sysconfig]# cd ~

   4: [root@DB-Server ~]# pwd

   5: /root

4:切换到根目录

   1: [root@DB-Server ~]# cd / 

   2: [root@DB-Server /]# 

5:切换到某个目录,例如/etc/sysconfig/

   1: [root@DB-Server ~]# cd /etc/sysconfig/

6: 返回进入当前目录前所在目录

   1: [root@DB-Server ~]# cd /etc/sysconfig/ 

   2: [root@DB-Server sysconfig]# cd - 

   3: /root