Linux Command: cd command learning and use, linux Command cd Learning

Source: Internet
Author: User

Linux Command: cd command learning and use, linux Command cd Learning

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:

1 [root @ localhostsoft] # pwd

2/opt/soft

3 [root @ localhostsoft] # cd ..

4 [root @ localhostopt] # cd ..//

5 [root @ localhost/] # pwd

6/

Note:

To enter the root directory of the system, you can use "cd .." to continue to return to the root directory.

Command:

Cd ../..//

Output:

1 [root @ localhostsoft] # pwd

2/opt/soft

3 [root @ localhostsoft] # cd ../..//

4 [root @ localhost/] # pwd

5/

6 [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:

1 [root @ localhostsoft] # pwd

2/opt/soft

3 [root @ localhostsoft] # cd

4 [root @ localhost ~] # Pwd

5/root

Command 2:

Cd ~

Output:

1 [root @ localhost ~] # Cd/opt/soft/

2 [root @ localhostsoft] # pwd

3/opt/soft

4 [root @ localhostsoft] # cd ~

5 [root @ localhost ~] # Pwd

6/root

Example 3: Jump to the specified directory

Command:

Cd/opt/soft

Output:

1 [root @ localhost ~] # Cd/opt/soft

2 [root @ localhostsoft] # pwd

3/opt/soft

4 [root @ localhostsoft] # cdjdk1.6.0 _ 16/

5 [root@localhostjdk1.6.0 _ 16] # pwd

6/opt/soft/jdk1.6.0 _ 16

7 [root@localhostjdk1.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:

1 [root @ localhostsoft] # pwd

2/opt/soft

3 [root @ localhostsoft] # cd-

4/root

5 [root @ localhost ~] # Pwd

6/root

7 [root @ localhost ~] # Cd-

8/opt/soft

9 [root @ localhostsoft] #

Example 5: Use the parameters of the previous command as the cd parameter.

Command:

Cd! $

Output:

1 [root @ localhostsoft] # cd! $

2cd-

3/root

4 [root @ localhost ~] # Cd! $

5cd-

6/opt/soft

7 [root @ localhostsoft] #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.