栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 系统运维 > 运维 > Linux > Linux命令手册 > 文件管理

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
转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/321.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号