linux如何使用cd命令进入目录,cd命令 – 切换目录

cd命令是”change directory”中单词的首字母缩写,其英文释义是改变目录,所以该命令的功能是从当前目录切换到指定目录。

其中目录的路径可分为绝对路径和相对路径。若目录名称省略,则切换至使用者的用户目录(也就是刚登录时所在的目录)。

另外,“~”也表示为用户目录的意思,“.”则是表示目前所在的目录,“..”则表示当前目录位置的上一级目录。

语法格式:cd [参数] [目录名]

常用参数:

-P如果切换的目标目录是一个符号链接,则直接切换到符号链接指向的目标目录

-L如果切换的目标目录是一个符号链接,则直接切换到符号链接名所在的目录

--仅使用”-“选项时,当前目录将被切换到环境变量”OLDPWD”对应值的目录

~切换至当前用户目录

..切换至当前目录位置的上一级目录

参考实例

将当前工作目录切换到dir目录,并使用pwd命令查看当前目录:

[root@linuxcool ~]# cd dir

[root@linuxcool dir]# pwd

/root/dir

使用“cd ~ ”和“cd .. ”命令进行目录的切换操作,并使用pwd命令查看当前目录:

注意:使用“cd ~ ”命令可以直接切换到当前用户目录,而“cd .. ”是切换到上一级目录。

[root@linuxcool dir]# pwd

/root/dir

[root@linuxcool dir]# cd ~

[root@linuxcool ~]# pwd

/root

[root@linuxcool dir]# pwd

/root/dir

[root@linuxcool dir]# cd ..

[root@linuxcool dir]# pwd

/root

使用“cd ../..”命令返回上两级目录:

[root@linuxcool dir_2]# pwd

/root/dir/dir_1/dir_2

[root@linuxcool dir_2]# cd ../..

[root@linuxcool dir]# pwd

/root/dir

使用“cd”命令返回当前用户目录。“cd -- ” 命令返回上一次所在目录:

[root@linuxcool dir_2]# pwd

/root/dir/dir_1/dir_2

[root@linuxcool dir_2]# cd

[root@linuxcool ~]# pwd

/root

[root@linuxcool ~]# cd -

/root/dir/dir_1/dir_2

[root@linuxcool dir_2]# pwd

/root/dir/dir_1/dir_2

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值