The Linuxcd command is the most basic command statement in Linux. other command statements are created on the cd command.
The Linux cd command is the most basic command statement in Linux. other command statements are created on the cd command.
Therefore, to learn common Linux commands, you must first learn how to use cd commands.
1. command format:
Cd [directory name]
2. command functions:
Switch the current directory to dirName
3. Common examples
Example 1: enter the system root directory
Command:
Cd/
Output:
[Root @ localhost ~] # Cd/
Note: go to the system root directory. Take a look at the ls command after the above command is executed. the current directory is already in the system root directory.
Command:
Cd... or cd ..//
Output:
Copy codeThe code is as follows:
[Root @ localhost soft] # pwd
/Opt/soft
[Root @ localhost soft] # cd ..
[Root @ localhost opt] # cd ..//
[Root @ localhost/] # pwd
/
Note:
To enter the root directory of the system, you can use "cd .." to continue to return to the root directory.
Command:
Cd ../..//
Output:
Copy codeThe code is as follows:
[Root @ localhost soft] # pwd
/Opt/soft
[Root @ localhost soft] # cd ../..//
[Root @ localhost/] # pwd
/
[Root @ localhost/] #
Note: run the cd command to access the parent directory of the current directory.
Example 2: run the cd command to enter the home directory of the current user.
"Current User home directory" and "system root directory" are two different concepts. There are two methods to enter the current user's home directory.
Command 1:
Cd
Output:
Copy codeThe code is as follows:
[Root @ localhost soft] # pwd
/Opt/soft
[Root @ localhost soft] # cd
[Root @ localhost ~] # Pwd
/Root
Command 2:
Cd ~
Output:
Copy codeThe code is as follows:
[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:
Copy codeThe code is as follows:
[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] #
Note:
Jump to the specified directory, starting from the root directory, and add/before the directory name. you can directly write the name of the subdirectory in the current directory.
Example 4: return the directory before entering this directory
Command:
Cd-
Output:
Copy codeThe code is as follows:
[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 parameters of the previous command as the cd parameter.
Command:
Cd! $
Output:
Copy codeThe code is as follows:
[Root @ localhost soft] # cd! $
Cd-
/Root
[Root @ localhost ~] # Cd! $
Cd-
/Opt/soft
[Root @ localhost soft] #
The following describes the most common Linux commands for linux cd.
Linux cd commands are the most common commands in linux. we need to use these commands almost all the time.
The cd command is also available in DOS. it has the same functions as the linux cd command, but there are also differences. let's explain it below.
Code:
Linux cd commands
1. name: cd
2. intended audience: all users
3. command Format: cd [dirName] (use spaces to separate cd and directories)
4. function: switch the current directory to dirName.
5. example:
[Snms @ snms/] $ cd/
[Snms @ snms/] $ ls
Bin dev home lost + found mnt proc sbin srv tmp var
Boot etc lib media opt root selinux sys usr
[Snms @ snms/] $ cd/boot
[Snms @ snms boot] $ ls
Config-2.6.27.5-117.fc10.i686 lost + found
Efi System. map-2.6.27.5-117.fc10.i686
Grub vmlinuz-2.6.27.5-117.fc10.i686
Initrd-2.6.27.5-117.fc10.i686.img
[Snms @ snms boot] $
6. tips for using linux cd commands:
Cd to go to the user's home directory;
Cd ~ Go to the user's home directory;
Cd-return the directory where it was located before entering the directory;
Cd .. back to the parent directory (if the current directory is "/", it is still "/"; ".." after execution );
Cd... returns the last two levels of directories;
Cd! $ Use the parameters of the previous command as the cd parameter.
The above is the difference between the linux cd command and the DOS cd command.