1. Command format.
cd [directory name]
2. Command function.
Switches the current directory to dirName
3. Common examples
3.1 Example 1: Enter the system root directory
Command: cd /
Output.
[root@localhost ~]# cd /
Explanation: Enter the system root directory. After the above command is executed, take the ls command to see if the current directory is already in the system root directory
Command: cd ...
or cd ... //
Output.
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd ...
[root@localhost opt]# cd . //
[root@localhost /]# pwd
/
Description.
To enter the system root directory you can use cd ...
Keep going back to reach the root directory
Command: cd ... /... //
Output.
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd ... /... //
[root@localhost /]# pwd
/...
[root@localhost /]# `
Description: Use the cd command to enter the parent directory of the current directory.
Example 2: Using the cd command to enter the current user’s home directory
The “current user home directory” and the “system root directory” are two different concepts. There are two ways to enter the current user home directory.
Command 1: cd
Output.
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd
[root@localhost ~]# pwd
/root
Command 2: cd ~
Output.
[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd ~
[root@localhost ~]# pwd
/root
Example 3: Jump to the specified directory
Command: cd /opt/soft
Output.
[root@localhost ~]# cd /opt/soft
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd jdk1.6.0_16/
[root@localhost jdk1.6.0_16]# pwd
/opt/soft/jdk1.6.0_16
[root@localhost jdk1.6.0_16]# `
Description.
Jump to the specified directory, starting from the root directory, add / before the directory name, and write the names of the subdirectories in the current directory directly
Example 4: Return to the directory you were in before entering this directory
Command: cd -
Output.
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]# cd -
/root
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd -
/opt/soft
[root@localhost soft]# `
Example 5: Use the arguments of the previous command as cd arguments.
Command: cd ! $
Output.
# cd ! $
cd -1 [root@localhost soft]# cd ! $
cd -
/root
[root@localhost ~]
/opt/soft
[root@localhost soft]#
Reference: