Home >Operation and Maintenance >Linux Operation and Maintenance >What is the command to enter the directory in linux?

What is the command to enter the directory in linux?

青灯夜游
青灯夜游Original
2022-04-13 16:23:0147889browse

The Linux command to enter the directory is "cd". The cd command is used to switch the working directory and can enter the specified directory. There are two syntaxes: 1. "cd [relative path or absolute path]"; 2. "cd [special character]", followed by special characters to express a fixed Meaning, for example, "cd ~username" means entering the home directory of the specified user.

What is the command to enter the directory in linux?

#The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

The Linux command to enter the directory is "cd".

cd command is the abbreviation of Change Directory. It is used to switch the working directory and enter the specified directory.

The basic format of the cd command is as follows:

cd [相对路径或绝对路径]

In addition, the cd command can be followed by some special symbols to express fixed meanings. Syntax:

cd [特殊字符]
Special symbols Function
~ Represents the home directory of the currently logged in user
~Username means switching to the home directory of the specified user
- represents the last directory
. represents the current directory
.. represents the upper-level directory

Their usage is:

1. Enter the home directory of the currently logged in user

cd ~
#表示回到自己的主目录,对于 root 用户,其主目录为 /root

cd
#没有加上任何路径,也代表回到当前登录用户的主目录

cd ~vbird
#代表切换到 vbird 这个用户的主目录,亦即 /home/vbird

2. Enter the current upper-level directory

cd ..
#表示切换到目前的上一级目录,亦即是 /root 的上一级目录的意思;

3. Return to the directory just now

cd -

[Example 1] Learn how to use cd -.

[root@localhost ~]# cd /usr/local/src
#进入/usr/local/src目录
[root@localhost src]# cd -
/root
[root@localhost ~]#
#"cd -"命令回到进入 src 目录之前的主目录
[root@localhost ~]# cd -
/usr/local/src
[root@localhost src]#
#再执行一遍"cd -"命令,又回到了 /usr/local/src 目录

【Example 2】Learn the usage of cd . and cd ...

[root@localhost ~]# cd /usr/local/src
#进入测试目录

[root@localhost src]# cd ..
#进入上级目录

[root@localhost local]# pwd
/usr/local
#pwd是査看当前所在目录的命令,可以看到我们进入了上级目录 /usr/local

[root@localhost local]# cd .
#进入当前目录

[root@localhost local]# pwd
/usr/local
#这个命令不会有目录的改变,只是告诉大家"."代表当前目录

Description: The pwd command is used to display the current directory

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the command to enter the directory in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn