cd命令

来源:互联网 发布:mac apache2下载 编辑:程序博客网 时间:2024/06/16 09:00

       cd命令用来切换工作目录至dirName。其中dirnNme表示可为绝对路径或相对路径。若目录名称省略,则变换至使用者的home directory(也就是刚login时所在的目录)。另外,~也表示为home directory的意思,.则是表示目前所在的目录,..则表示目前目录位置的上一层目录。

1、命令格式:

      cd [选项] [目录]

2、命令功能:

      切换当前目录至dirName

3、常用范例

实例一:进入系统根目录

       命令:

                cd /

       命令输出:

                [root@localhost ~]# cd /

                  [root@localhost /]#

          说明:进入系统跟目录,上面命令执行完后拿ls命令看一下,当前目录已经到系统跟目录了

实例二:进入用户主目录

       命令:

               cd

           或

               cd ~

       命令输出:                 

                  [root@localhost test2]# cd
                  [root@localhost ~]# 

                  或 

                  [root@localhost test3]# cd ~
                  [root@localhost ~]#

 

实例三:返回上级目录         

       命令:

                cd ..

       命令输出:                 

                    [root@localhost ~]# cd test
                    [root@localhost test]# cd ..
                    [root@localhost ~]#

         说明:若当前目录为“/”,则执行完后还在“/”

实例四:返回上两级目录

       命令:

                cd ../..

       命令输出:               

                   [root@localhost ~]# cd test
                   [root@localhost test]# cd test1
                   [root@localhost test1]# cd ../..
                   [root@localhost ~]#

 

实例五:返回进此目录之前所在的目录       

       命令:

                cd -

        命令输出:             

                    [root@localhost ~]# cd test/test1/test2/test3
                    [root@localhost test3]# cd /
                    [root@localhost /]# cd -
                    /root/test/test1/test2/test3
                    [root@localhost test3]#

 

实例六:把上个命令的参数作为cd参数使用

       命令:

               cd !$

       命令输出:              

                  [root@localhost ~]# cd test/test1/test2/test3
                  [root@localhost test3]# cd /
                  [root@localhost /]# cd -
                  /root/test/test1/test2/test3
                  [root@localhost test3]# cd !$
                  cd -
                  /
                  [root@localhost /]# cd !$
                  cd -
                  /root/test/test1/test2/test3
                  [root@localhost test3]#

 

实例七:跳转到指定目录(目录可以是相对路径也可是绝对路径)

        命令:

                 cd ./test/test1/test2/test3

                 cd /root/test/test1/test2/test3

        命令输出:

                结果1:               

                  [root@localhost ~]# cd ./test/test1/test2/test3
                  [root@localhost test3]#

               结果2:

                  [root@localhost ~]# cd /root/test/test1/test2/test3
                  [root@localhost test3]#

原创粉丝点击