Linux系统中,cd这个命令使用的非常多,当然也很重要。
1. cd
cd [目录名] 切换当前目录至dirName,即目标路径。(cd和目录之间使用空格隔开)
2. cd / (“/”表示的是根目录)
说明:进入系统根目录
进入系统根目录,上面命令执行完后拿ls命令看一下,当前目录已经到系统根目录了 。
3. cd .. 或者 cd .. // (”.”的意思就是当前目录, “..”的意思就是上级目录)
说明:进入系统根目录可以使用“ cd .. ”一直退,就可以到达根目录 。
[mt555@localhost /]$ cd home
[mt555@localhost home]$ pwd
/home
[mt555@localhost home]$ cd ..
[mt555@localhost /]$ cd ..//
[mt555@localhost /]$ pwd
/
4.cd ../.. // 或者 cd ../.. 返回上两级目录;
[mt555@localhost tmp]$ pwd
/tmp
[mt555@localhost tmp]$ cd ../..//
[mt555@localhost /]$ pwd
/
[mt555@localhost /]$
5.使用 cd 命令进入当前用户主目录
“当前用户主目录”和“系统根目录”是两个不同的概念。
进入当前用户主目录有两个方法。
- cd
[mt555@localhost home]$ pwd
/home
[mt555@localhost home]$ cd
[mt555@localhost ~]$ pwd
/home/mt555
[mt555@localhost ~]$
- cd ~
[mt555@localhost ~]$ cd Desktop
[mt555@localhost Desktop]$ pwd
/home/mt555/Desktop
[mt555@localhost Desktop]$ cd ~
[mt555@localhost ~]$ pwd
/home/mt555
[mt555@localhost ~]$
说明:跳转到指定目录,从根目录开始,目录名称前加 / ,当前目录内的子目录直接写名称即可.
6. cd -
说明:返回进入此目录之前所在的目录。
[mt555@localhost ~]$ cd Desktop
[mt555@localhost Desktop]$ pwd
/home/mt555/Desktop
[mt555@localhost Desktop]$ cd -
/home/mt555
[mt555@localhost ~]$ pwd
/home/mt555
[mt555@localhost ~]$ cd -
/home/mt555/Desktop
[mt555@localhost Desktop]$
7.cd !$
说明:把上个命令的参数作为cd参数使用。
[mt555@localhost Desktop]$ cd !$
cd -
/home/mt555
[mt555@localhost ~]$ cd !$
cd -
/home/mt555/Desktop
[mt555@localhost Desktop]$