CD: Switch directories

Source: Internet
Author: User

CD command

1. Detailed command

"Feature description"

The CD command is the acronym for each word in change directory, and its function is to switch from the current working directory to the specified working directory.

"Syntax format"

CD [option] [dir]

CD [options] [contents]

Description

      1. Note the CD command and the following options and directories, with at least one space between each element.
      2. Parameters such as options and directories after the CD command can be omitted. By default, the CD command is executed separately to switch to the home directory of the currently logged-on user (defined by the system environment variable home).
      3. The CD is a built-in command for the bash shell, and the Help CD is required to view the system assistance for that command.

"Parameter description"

      1. Parameter options and descriptions for the CD command
Parameter options Explanatory note (with "Δ" as the focus)
-P If the target directory for the switch is a soft link, it switches directly to the real physical destination directory that the soft link points to, and is similar to the-P option for the PWD command, which is not commonly used.
-L function with-p in contrast, if the target directory of the switch is a soft link, the switch directly to the directory where the soft link resides, and the PWD command's-l option function is similar, this parameter is not commonly used.
- When only the "-" option is used, the directory path of the corresponding value of the system environment variable "OLDPWD" is switched from the current directory to the directory path of the current user's last location Δ
~ When only the "~" option is used, the directory path to the corresponding value of the system environment variable "home" will be switched from the current directory, i.e. the path of the current user's home directory Δ
.. When you use only the ".." option, you will switch from the current directory to the path of the previous directory in the current directory Δ

2. Use Example

Example 1: Entering the system/etc directory (CD/ETC)

[Email protected] ~]# pwd
/root #在linux系统中, each user has their own home directory, by default, users will enter their home directory after logging into the system. The root user's home directory is/root, the home directory of the normal user is the/home/user name by default
[[email protected] ~]# cd/etc/#切换到/etc/Directory
[Email protected] etc]# pwd
/etc #此时已经进入/etc directory

Example 2: Switch to the top level directory of the current directory (CD: )

[[email protected] etc]# cd/usr/local/src/#切换到/usr/local/src directory.
[Email protected] src]# pwd
/usr/local/src
[Email protected] src]# CD. # "CD.." Equivalent to the previous level of the directory name, can also be written as ". /”。
[Email protected] local]# pwd
/usr/local #此时切换到了/usr/local

Example 3: Enter the parent directory of the current directory (CD: /.. /)

[Email protected] ~]# cd/usr/local/src/
[Email protected] src]# pwd
/usr/local/src
[Email protected] src]# CD. /.. /#退到当前目录的上两级目录 to the '/usr ' directory
[Email protected] usr]# pwd
/usr

Tips:

As long as the directory has enough levels, you can continue to do so "CD. /.. /.. /", know to return to"/"so far.

Example 4: Returns the directory where the current user was last (CD-).

[Email protected]/]# cd/usr/local/src/
[Email protected] src]# pwd
/usr/local/src
[[Email protected] src]# CD #cd命令不接收任何参数时, from the environment variable home get pathname, that is, switch to the current user home directory.

[Email protected] ~]# pwd #当前用户的工作路径为/root
/root
[[email protected] ~]# cd-#执行 "CD-", the CD will get the pathname based on the corresponding value of the environment variable OLDPWD.
/USR/LOCAL/SRC #即切换到了当前用户上一次的工作路径 "/usr/local/src"
[Email protected] src]# pwd
/usr/local/src

  

Example 5: Go to the current user's home directory (CD ~)

[Email protected] src]# pwd
/usr/local/src
[[Email protected] src]# CD ~ # "~" The upper left corner of the keyboard ESC built below the wave symbol, representing the home directory.
[Email protected] ~]# pwd
/root #切换到当前用户的家目录了.

CD: Switch directories

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.