cd命令在linux中,用于切换目录,是linux中最经常使用的命令之一。
linux
命令功能bash
切换当前目录至指定目录ide
命令格式spa
cd [diretory]
orm
经常使用范例ip
例一:进入到/目录ci
命令:it
cd /
输出:class
[root@oldboylinux ~]# cd / [root@oldboylinux /]# pwd / [root@oldboylinux /]#
用pwd命令能够查看当前所在目录的绝对路径。network
例二:返回当前目录的上一层目录,使用../..的用法能够返回上上层目录,../../..,以此类推。
命令:
cd ..
输出:
[root@oldboylinux network-scripts]# pwd /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]# cd .. [root@oldboylinux sysconfig]# pwd /etc/sysconfig [root@oldboylinux sysconfig]# cd .. [root@oldboylinux etc]# pwd /etc [root@oldboylinux ~]# cd /etc/sysconfig/network-scripts/ [root@oldboylinux network-scripts]# pwd /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]# cd ../.. [root@oldboylinux etc]# pwd /etc [root@oldboylinux etc]#
例三:进入本身的家目录
命令:
cd #不接任何参数默认返回用户家目录 cd ~ #"~"表示用户的家目录
输出:
[root@oldboylinux network-scripts]# cd [root@oldboylinux ~]# pwd /root [root@oldboylinux ~]# cd /etc/sysconfig/network-scripts/ [root@oldboylinux network-scripts]# cd ~ [root@oldboylinux ~]# pwd /root [root@oldboylinux ~]#
例四:返回进入此目录以前的目录
命令:
cd -
输出:
[root@oldboylinux network-scripts]# cd ~ [root@oldboylinux ~]# pwd /root [root@oldboylinux ~]# cd - /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]# pwd /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]# cd - /root [root@oldboylinux ~]#
例五:把上个命令的参数做为cd的参数使用
命令:
cd !$
输出
[root@oldboylinux ~]# cd /etc/sysconfig/network-scripts/ [root@oldboylinux network-scripts]# cd - /root [root@oldboylinux ~]# cd - /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]# cd !$ cd - /root [root@oldboylinux ~]# cd !$ cd - /etc/sysconfig/network-scripts [root@oldboylinux network-scripts]#