The CD command in Linux, used to switch directories, is one of the most commonly used commands in Linux.
Command function
Switch the current directory to the specified directory
Command format
CD [Diretory]
Common examples
Example one: Go to/directory
Command:
CD/
Output:
[[Email protected] ~]# CD/[[email protected]/]# Pwd/[[email protected]/]#
Use the PWD command to view the absolute path to the current directory.
Example two: Returns the current directory of the previous level of the directory, using: /.. The usage can be returned to the upper-level directory,. /.. /.., and so on.
Command:
Cd..
Output:
[Email protected] network-scripts]# Pwd/etc/sysconfig/network-scripts[[email protected] network-scripts]# CD. [Email protected] sysconfig]# Pwd/etc/sysconfig[[email protected] sysconfig]# CD. [[email protected] etc]# pwd/etc[[email protected] ~]# Cd/etc/sysconfig/network-scripts/[[email protected] network-scripts]# Pwd/etc/sysconfig/network-scripts[[email protected] network-scripts]# CD. /.. [Email protected] etc]# Pwd/etc[[email protected] etc]#
Example three: Go to your home directory
Command:
cd# not take any parameters by default returned to the user home directory CD ~# "~" indicates the user's home directory
Output:
[[email protected] network-scripts]# cd[[email protected] ~]# pwd/root[[email protected] ~]# cd/etc/sysconfig/ Network-scripts/[[email protected] network-scripts]# CD ~[[email protected] ~]# Pwd/root[[email protected] ~]#
Example four: Returning a directory before entering this directory
Command:
CD-
Output:
[[Email protected] network-scripts]# CD ~[[email protected] ~]# Pwd/root[[email protected] ~]# CD-/etc/sysconfig/network -scripts[[email protected] network-scripts]# Pwd/etc/sysconfig/network-scripts[[email protected] network-scripts]# CD-/root[[email protected] ~]#
Example five: Use the parameters of the previous command as CD parameters
Command:
CD!$
Output
[[email protected] ~]# Cd/etc/sysconfig/network-scripts/[[email protected] network-scripts]# CD-/root[[email Protected] ~]# CD-/etc/sysconfig/network-scripts[[email protected] network-scripts]# CD! $CD-/root[[email protected] ~ ]# CD! $CD-/etc/sysconfig/network-scripts[[email protected] network-scripts]#
One Linux command per day-CD