What is a host directory in linux

青灯夜游
Release: 2023-04-17 09:51:19
Original
2513 people have browsed it

In Linux, the host directory refers to the home directory, which is usually used to save user files; when a user logs in to the system, the location after entering is "/home". The home directory of the root user is "/root". The home directory is usually represented by a tilde "~". There are three ways to enter the home directory: 1. Use the "cd" command directly; 2. Use the "cd ~" command; 3. Use the absolute path and execute "cd / home/xxxuser" command.

What is a host directory in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the host directory in Linux

The so-called host directory is the operating system designed for the current user to store files and work the default directory. For example, the "My Documents" directory in Windows is the host directory designed for us by Windows. There is also a host directory in Linux, that is, the home directory.

A user logs in to the system. After entering, the location is /home. The home directory of Linux is usually used to save the user's files. The root user's home directory is /root.

Linux’s home directory is usually represented by a tilde “~”. For example, if the current user's home directory is /home/haicoder, then entering cd or cd ~ or cd /home/haicoder or cd $HOME are equivalent.

This habit originated from the popular Lear-Siegler ADM-3A terminal machine in the 1970s. On this machine, the tilde and "home" key (used to move the cursor to the far left) happened to be on the same key.

In Linux, there are many ways to enter the user's home directory.

Explanation

The user’s home directory can be found in item 6 of /etc/passwd

[root@www ~]# head -n 4 /etc/passwdroot:x:0:0:root:/root:/bin/bash <==等一下做为底下说明用 bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin
Copy after login

Home directory:

This is The user's home directory, taking the above example, root's home directory is /root, so when root logs in, it will immediately go to /root It’s in the catalog! hehe! If you have an account with a particularly large space, what should you do if you want to move the account's home directory to another hard drive? correct! You can make modifications in this field! The default user home directory is in The /home/yourIDname

directory is a special file for organizing files in the Linux system. To enable users to better use directories, we introduce some basic concepts about directories.

(1) Working directory and user home directory

Logically speaking, after the user logs in to the Linux system, he is in a certain directory at all times. This directory It is called the working directory or current directory (Working Directory). The working directory can be changed at any time. When a user initially logs into the system, his or her home directory becomes his or her working directory. The working directory is represented by "." and its parent directory is represented by "..".

The user home directory is created by the system administrator when adding users (it can also be changed later). Each user has his own home directory, and the home directories of different users are generally different from each other.

When a user first logs in to the system, his working directory is the user's home directory, which is usually the same as the user's login name.

Users can reference their home directory through a ~ character.

For example, the command

/home/WANG$ cat ~/class/software_1
Copy after login

has the same meaning as the following command

/home/WANG$ cat /home/WANG/class/software_1
Copy after login
Copy after login

. The shell will replace the ~ character with the name of the user's home directory. After the directory hierarchy is created, users can put relevant files into the corresponding directories to organize the files.

(2) Path

As the name suggests, a path refers to a path from a certain directory level in the tree directory to a certain file. The main component of this path is the directory name, separated by "/". The location of any file in the file system is determined by the corresponding path.

When users access a file, they must provide the path where the file is located. Paths are divided into relative paths and absolute paths. An absolute path refers to a path starting from the "root", also known as a full path; a relative path refers to a path starting from the user's working directory.

It should be noted that there is only one absolute path and one relative path to a certain file in the tree directory structure. The absolute path is determined and unchanged, while the relative path changes continuously as the user's working directory changes. This will be of great benefit to us in using certain commands such as cp and tar in the future.

When a user wants to access a file, he or she can refer to it by a path name, and can refer to it based on the relative position of the file to be accessed and the user's working directory, without listing the full path name of the file. For example, user WANG has a directory named class, and there are two files in this directory: software_1 and hardware_1. If user WANG wants to display the file named software_1 in his class directory, he can use the following command:

/home/WANG$ cat /home/WANG/class/software_1
Copy after login
Copy after login

The user can also reference the file based on the relative position of the file software_1 and the current working directory. At this time, the command is:

  /home/WANG$ cat class/software_1
Copy after login

Extended knowledge:

Use the pwd command in Linux to view the full path of the "current working directory". Simply put, whenever you operate in the terminal, you will have a current working directory.

When you are not sure of the current location, pwd will be used to determine the exact location of the current directory in the file system.

1. Command format:

pwd [选项]
Copy after login

2. Command function:

View the full path of the "current working directory"

3. Commonly used parameters:

Generally without any parameters

If the directory is a link:

Format:pwd -PDisplay The actual path, rather than using a link path.

4. Commonly used examples:

Example 1: Use the pwd command to view the full path of the default working directory

[root@localhost ~]# pwd /root [root@localhost ~]#
Copy after login

Example 2:

[root@localhost ~]# cd /opt/soft/ [root@localhost soft]# pwd /opt/soft [root@localhost soft]#
Copy after login

Example 3: When connecting to a directory, pwd -P displays the actual path instead of using the link path; pwd displays the link path

Command:

[root@localhost soft]# cd /etc/init.d [root@localhost init.d]# pwd /etc/init.d [root@localhost init.d]# pwd -P /etc/rc.d/init.d [root@localhost init.d]#
Copy after login

Example 4:

/bin/pwd [选项]
Copy after login

Output:

[root@localhost init.d]# /bin/pwd /etc/rc.d/init.d [root@localhost init.d]# /bin/pwd --help [root@localhost init.d]# /bin/pwd -P /etc/rc.d/init.d [root@localhost init.d]# /bin/pwd -L /etc/init.d [root@localhost init.d]#
Copy after login

Example 5: The current directory is deleted, but the pwd command still displays that directory

[root@localhost init.d]# cd /opt/soft [root@localhost soft]# mkdir removed [root@localhost soft]# cd removed/ [root@localhost removed]# pwd /opt/soft/removed [root@localhost removed]# rm ../removed -rf [root@localhost removed]# pwd /opt/soft/removed [root@localhost removed]# /bin/pwd /bin/pwd: couldn't find directory entry in “..” with matching i-node [root@localhost removed]# cd [root@localhost ~]# pwd /root [root@localhost ~]#
Copy after login

Related recommendations: "Linux Video Tutorial"

##cd Use directly The cd command can enter the current user's home directory. cd ~ Use the cd ~ command to enter the current user's home directory. cd /home/xxxuser Using the absolute path, you can also enter the user's home directory.
Command Description

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!