Linux Learning Note 2---command CD

Source: Internet
Author: User
Tags parent directory

Linux CD commands can be said to be the most basic Linux command statements, the other command statements to operate, are based on the use of the CD command. CD commands are relatively simple, but there are some tricks that are worth learning.

Therefore, to learn the common Linux commands, the first step is to learn How to use the CD command skills.

The CD command is used to switch the working directory to dirname. Where dirname notation can be either an absolute path or a relative path. If the directory name is omitted, it is transformed to the user's home directory (that is, the directory where login was first). In addition, the ~ is also expressed as the meaning of home directory, which is the current directory. Represents the previous level of directory at the current directory location.
1. Command format:

cd [ directory name ]

cd command common parameter options:

-P If the destination directory you want to switch to is a symbolic connection, switch directly to the destination directory that the symbolic connection is pointing to

-L If the destination directory that you want to switch is a symbolic connection, switch directly to the directory that the character connection name represents, not the destination directory that the symbolic connection points to.

-When only the "-" option is applied, the current working directory is switched to the directory represented by the environment variable "OLDPWD".


2. Command function:

Toggle current directory to DirnamE

3. Common examples

3.1 Example One: Enter the system root directory

Command:

CD/

Output:

[[Email protected] ~]# CD/

Note: Enter the system root directory, the above command after the execution of the LS command to see, the current directory has been to the system root directory

Command:

Cd..

Output :

1 [[Email protected] soft]# pwd
2/opt/soft
3 [[Email protected] soft]# CD.
4 [[Email protected] opt]# CD. //
5 [[email protected]/]# pwd
6/

Description

Enter the system root directory to use the CD. " always back, you can reach the root directory

Command:

Cd.. /.. /

Output:

1 [[Email protected] soft]# pwd
2/opt/soft
3 [[Email protected] soft]# CD. /.. //
4 [[email protected]/]# pwd
5/
6 [[Email protected]/]#

Description: Use the CD command to implement the parent directory into the parent directory of the current directory.

Example 2: Using the CD command to enter the current user home directory

The "Current User home Directory" and "system root" are two different concepts. There are two methods to enter the current user home directory.

Command 1:

Cd

Output:

1 [[Email protected] soft]# pwd
2/opt/soft
3 [[Email protected] soft]# CD
4 [[email protected] ~]# pwd
5/root

Command 2:

CD ~

Output:

1 [[Email protected] ~]# cd/opt/soft/
2 [[email protected] soft]# pwd
3/opt/soft
4 [[Email protected] soft]# CD ~
5 [[email protected] ~]# pwd
6/root

Example 3: Jump to a specified directory

Command:

Cd/opt/soft

Output:

1 [[Email protected] ~]# Cd/opt/soft
2 [[email protected] soft]# pwd
3/opt/soft
4 [[Email protected]st soft]# CD jdk1.6.0_16/
5 [[email protected] jdk1.6.0_16]# pwd
6/opt/soft/jdk1.6.0_16
7 [[Email protected] jdk1.6.0_16]#

Description

Jump to the specified directory, starting from the root directory, the directory name plus /, The current directory in the subdirectory directly write the name can be

Example four: Return to the directory in which it was before entering this directory

Command:

CD-

Output:

1 [[Email protected] soft]# pwd
2/opt/soft
3 [[Email protected] soft]# CD-
4/root
5 [[email protected] ~]# pwd
6/root
7 [[Email protected] ~]# CD-
8/opt/soft
9 [[Email protected] soft]#

Example five: Use the parameters of the previous command as CD parameters.

Command:

CD!$

Output:

1 [[Email protected] soft]# CD!$
2 CD-
3/root
4 [[Email protected] ~]# CD!$
5 CD-
6/opt/soft
7 [[Email protected] soft]#

The CD command that I used to use:

The CD enters the user's home directory;

CD ~ Enter the user's home directory;

CD-Returns the directory where the directory was before it entered;

Cd.. Return to the parent directory (if the current directory is "/", then "/"; "..." after execution) The meaning of the parent directory);

Cd.. /.. Return to the top level two directory;

CD!$ Use the parameters of the previous command as CD parameters.

Linux Learning Note 2---command CD

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.