What is a host directory in linux

Apr 17, 2023 am 09:51 AM
linux

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.

##cdUse 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/xxxuserUsing the absolute path, you can also 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 -P Display 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&#39;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"

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

See all articles