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

What is the command to enter a directory in Linux?

青灯夜游
青灯夜游Original
2021-04-22 15:44:0224206browse

The Linux command to enter the directory is "cd". The function of this command is to switch to the specified directory. The syntax format is "cd [dirName]". The parameter "dirName" indicates the target directory to be switched, which can be an absolute path or a relative path; if the directory name is omitted, it will change to the user's home directory.

What is the command to enter a directory in Linux?

#The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.

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

Linux The cd command can be said to be the most basic command statement in Linux. Other command statements are based on the use of the cd command.

So, to learn common Linux commands, you must first learn how to use the cd command.

1. Command format:

cd [dirName]
  • dirName: The target directory to be switched.

2. Command function:

Switch the current directory to dirName

dirName representation can be an absolute path or relative path. If the directory name is omitted, it will change to the user's home directory (that is, the directory where the user just logged in).

In addition, ~ also means the home directory, . means the current directory, .. means the current directory The directory above the location.

3. Command usage

① When no parameters are added, the default is to switch to the user’s home directory

② Connect the absolute path or relative path , switch to the corresponding directory

③ Connect special symbols and enter the corresponding directory

~ to enter the user’s home directory;

-Return to the directory you were in before entering this directory;

..Return to the upper directory;

../..Return to the upper two levels Directory;

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

4. Command examples

Example 1: Switch to the user’s home directory

[root@lianxi tmp]# cd
[root@lianxi ~]#

Example 2: Enter other directories with absolute paths

[root@lianxi ~]# cd /tmp/TEST/
[root@lianxi TEST]#

Example 3: Relative path to enter other directories

[root@lianxi TEST]# cd ../1d/
[root@lianxi 1d]#

Example 4: ~Enter the user’s home directory

[root@lianxi 1d]# cd ~
[root@lianxi ~]#

Example 5: Return to the directory where you were before entering this directory

[root@lianxi ~]# cd -
/tmp/1d
[root@lianxi 1d]#

Example 6: Return to the upper directory

[root@lianxi 1d]# cd ..
[root@lianxi tmp]#

Example 7: Use the parameters of the previous command as cd parameters

[root@lianxi tmp]# cd !$
cd ..
[root@lianxi /]#

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the command to enter a 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