• 技术文章 >运维 >linux运维

    linux cd命令怎么用?

    青灯夜游青灯夜游2020-11-02 17:19:49原创5871

    linux cd命令用于切换当前工作目录,语法格式“cd [dirName]”,其中dirName表示法可为绝对路径或相对路径;若目录名称省略,则变换至使用者的home目录,即刚login时所在的目录。

    相关推荐:《Linux视频教程

    Linux cd命令用于切换当前工作目录至 dirName(目录参数)。

    其中 dirName 表示法可为绝对路径或相对路径。若目录名称省略,则变换至使用者的 home 目录 (也就是刚 login 时所在的目录)。

    另外,"~" 也表示为 home 目录 的意思,"." 则是表示目前所在的目录,".." 则表示目前目录位置的上一层目录。

    一、Linux cd命令语法

    cd [dirName]

    dirName:要切换的目标目录。

    二、Linux cd命令实例

    跳入test目录:

    [root@/root/linuxdaxue.com]#cd testDir/
    [root@/root/linuxdaxue.com/testDir]#ls
    file1  file2  file3

    跳至上层目录

    [root@/root/linuxdaxue.com/testDir]#cd ..
    [root@/root/linuxdaxue.com]#ls
    testDir

    跳至上上层目录

    [root@/root/linuxdaxue.com/testDir]#cd ../../
    [root@/root]#ls

    跳入用户主目录

    [root@/root/linuxdaxue.com/testDir]#ls
    file1  file2  file3
    [root@/root/linuxdaxue.com/testDir]#cd ~/
    [root@/root]#pwd
    /root

    使用绝对路径

    [root@/root]#cd /root/linuxdaxue.com/testDir
    [root@/root/linuxdaxue.com/testDir]#ls
    file1  file2  file3

    使用环境变量

    [root@/root]#cd $TEST_PATH
    [root@/root/linuxdaxue.com/testDir]#ls
    file1  file2  file3

    跳入上次使用目录

    [root@/root]#pwd
    /root
    [root@/root]#cd -
    /root/linuxdaxue.com/testDir
    [root@/root/linuxdaxue.com/testDir]#

    cd命令比较简单,主要用来切换工作目录,希望大家能熟练掌握。

    更多编程相关知识,请访问:编程入门!!

    以上就是linux cd命令怎么用?的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:linux cd命令
    上一篇:locate指令是什么 下一篇:linux下怎么安装php
    VIP会员

    相关文章推荐

    • linux下修改ip地址的方法• linux如何线上安装mysql• linux下怎么通过命令行方式获取IP• linux下如何使用grep命令查看进程• linux下如何使用mv命令移动文件到指定目录

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网