The Linux cd command can be said to be the most basic command statement in Linux. Other command statements are based on the use of the cd command.
Therefore, to learn common Linux commands, you must first learn how to use the cd command.
1. Command format:
cd [directory name]
2. Command function:
Switch the current directory to dirName
3. Common examples
3.1 Example 1: Enter the system root directory
Command:
cd /
Output:
[root@localhost ~]# cd /
Note: Enter the system root directory. After executing the above command, use the ls command to see that the current directory has reached the system root directory
Command:
cd .. or cd .. //
Output:
Description:
To enter the root directory of the system, you can use "cd .." to back out until you reach the root directory
Command:
cd ../.. //
Output:
Instructions: Use the cd command to enter the parent directory of the parent directory of the current directory.
Example 2: Use the cd command to enter the current user’s home directory
"Current user home directory" and "system root directory" are two different concepts. There are two ways to enter the current user's home directory.
Command 1:
cd
Output:
Command 2:
cd ~
Output:
Example 3: Jump to the specified directory
Command:
cd /opt/soft
Output:
Description:
Jump to the specified directory, starting from the root directory, add / before the directory name, and just write the name of the subdirectory in the current directory
Example 4: Return to the directory you were in before entering this directory
Command:
cd -
Output:
Example 5: Use the parameters of the previous command as cd parameters.
Command:
cd !$
Output: