学习啦 > 学习电脑 > 操作系统 > Linux教程 > Linux cd命令怎么使用

Linux cd命令怎么使用

时间: 孙胜龙652 分享

Linux cd命令怎么使用

学习啦在线学习网   cd命令式Linux命令中最基本的命令,也是最常用的命令之一,在使用Linux命令时几乎都要用到cd命令,所以学习Linux命令,cd命令是必须要掌握的,下面随小编一起来详细了解下cd命令吧。

  1. 命令格式:

  cd [目录名]

  2. 命令功能:

  切换当前目录至dirName

  3. 常用范例

学习啦在线学习网   3.1 例一:进入系统根目录

  命令:

  cd /

  输出:

学习啦在线学习网   [root@localhost ~]# cd /

学习啦在线学习网   说明:进入系统根目录,上面命令执行完后拿ls命令看一下,当前目录已经到系统根目录了

  命令:

  cd 。。 或者 cd 。。 //

  输出:

学习啦在线学习网   1 [root@localhost soft]# pwd

  2 /opt/soft

  3 [root@localhost soft]# cd 。。

学习啦在线学习网   4 [root@localhost opt]# cd 。。//

  5 [root@localhost /]# pwd

  6 /

  说明:

学习啦在线学习网   进入系统根目录可以使用“ cd 。。 ”一直退,就可以到达根目录

  命令:

学习啦在线学习网   cd 。。/。。 //

  输出:

  1 [root@localhost soft]# pwd

学习啦在线学习网   2 /opt/soft

  3 [root@localhost soft]# cd 。。/。。 //

学习啦在线学习网   4 [root@localhost /]# pwd

  5 /

学习啦在线学习网   6 [root@localhost /]#

  说明:使用cd 命令实现进入当前目录的父目录的父目录。

学习啦在线学习网   例2:使用 cd 命令进入当前用户主目录

  “当前用户主目录”和“系统根目录”是两个不同的概念。进入当前用户主目录有两个方法。

  命令1:

  cd

  输出:

  1 [root@localhost soft]# pwd

学习啦在线学习网   2 /opt/soft

  3 [root@localhost soft]# cd

学习啦在线学习网   4 [root@localhost ~]# pwd

  5 /root

  命令2:

  cd ~

  输出:

  1   [root@localhost ~]# cd /opt/soft/

  2   [root@localhost soft]# pwd

  3   /opt/soft

学习啦在线学习网   4   [root@localhost soft]# cd ~

  5   [root@localhost ~]# pwd

学习啦在线学习网   6   /root

  例3:跳转到指定目录

  命令:

学习啦在线学习网   cd /opt/soft

  输出:

学习啦在线学习网   1 [root@localhost ~]# cd /opt/soft

  2 [root@localhost soft]# pwd

学习啦在线学习网   3 /opt/soft

  4 [root@localhost soft]# cd jdk1.6.0_16/

  5 [root@localhost jdk1.6.0_16]# pwd

  6 /opt/soft/jdk1.6.0_16

学习啦在线学习网   7 [root@localhost jdk1.6.0_16]#

  说明:

  跳转到指定目录,从根目录开始,目录名称前加 / ,当前目录内的子目录直接写名称即可

  例四:返回进入此目录之前所在的目录

  命令:

  cd -

  输出:

  1 [root@localhost soft]# pwd

  2 /opt/soft

学习啦在线学习网   3 [root@localhost soft]# cd -

  4 /root

  5 [root@localhost ~]# pwd

  6 /root

学习啦在线学习网   7 [root@localhost ~]# cd -

学习啦在线学习网   8 /opt/soft

学习啦在线学习网   9 [root@localhost soft]#

学习啦在线学习网   例五:把上个命令的参数作为cd参数使用。

  命令:

  cd !$

  输出:

  1 [root@localhost soft]# cd !$

  2 cd -

  3 /root

  4 [root@localhost ~]# cd !$

  5 cd -

  6 /opt/soft

学习啦在线学习网   7 [root@localhost soft]#

  上面就是Linux cd命令的介绍了,cd命令可以说是Linux使用率最高的两个命令之一,以后你在Linux的操作中会经常使用到它。

304135