linux命令_cd_切换目录

cd (change directory)

切换到特定目录,无参数时切换至用户家目录

格式

cd [-L|[-P [-e]]] [dir]

参数说明

  • -L 追踪链接文件,默认选项
  • -P 使用物理目录,不追踪链接文件
  • -e

特殊符号代表的目录

  • ~ 用户家目录
  • . 当前目录或工作目录
  • .. 当前目录的父目录
  • - 上次所在的工作目录
    ※ 使用pwd 命令可以查看当前目录

返回值

如果切换目录成功,则返回0,切换目录失败则返回非0(CentOS7 为1)

使用实例

  • 切换到家目录:cdcd ~
  • 切换到根目录:cd /
  • 返回值测试:当切换的对象目录不存在,或者没有访问权限的时候返回值为1,切换成功则返回0.

    [fish@localhost ~]$ cd /fish
    bash: cd: /fish: No such file or directory
    [fish@localhost ~]$ echo $?
    1
    [fish@localhost ~]$ cd /root/
    bash: cd: /root/: Permission denied
    [fish@localhost ~]$ echo $?
    1

补充

  • cd 为内建命令
    [fish@localhost ~]$ type cd
    cd is a shell builtin
  • 查看帮助文档需要用help cd

猜你喜欢

转载自www.cnblogs.com/Assaltyfish/p/10071525.html
今日推荐