Home > Operation and Maintenance > Linux Operation and Maintenance > Technical answers to the definition and specifications of linux under /

Technical answers to the definition and specifications of linux under /

WBOY
Release: 2022-02-14 18:35:05
forward
1686 people have browsed it

This article summarizes some basic concepts of Linux for you. The file system in Linux and UNIX is a tree file structure with "/" as the root. "/" is the root directory in Linux and UNIX. Similarly It is also the starting point of the file system. I hope it will be helpful to everyone.

Technical answers to the definition and specifications of linux under /

The file system in Linux and UNIX is a tree file structure with / as the root, / is the root directory in Linux and UNIX , which is also the starting point of the file system. All files and directories are located under the / path, including /usr, /etc, /bin, /home, etc. that we often hear. In the early UNIX systems, each manufacturer defined the naming structure of its own file system, which was confusing and difficult to distinguish.

In order to avoid this naming confusion problem on Linux systems, the Linux file system hierarchy standard FSSTND (FileSystem Standard) was launched in 1994. Later, the UNIX team changed FSSTND It was carried forward and became the later FHS (FileSystem Hierarchy Standard).

The FHS standard enables many Linux distributions (Linux distributions) to have a unified file system naming standard. In other words: FHS is a file system naming standard. Generally speaking, Linux distributions need to follow the

  • directory structure and directory content
  • permissions of file types

However, FHS only defines There are two levels of specifications. The first level is what file data should be placed in each directory below /, such as /etc and setting files need to be placed below, /bin and /sbin You need to put executable files, etc. below; the second layer is defined for the two directories /usr and /var, such as /usr/share Shared data needs to be placed, /var/log needs to contain system login files, etc.

Now let me introduce to you what definitions and specifications Linux has under /.

FHS Specifications

The specifications I introduce below are only part of the directories and files specified in the FHS document. The complete standards are available online at http://www.pathname.com/fhs/ get.

First of all, let’s introduce the importance and significance of the root directory:

The root directory is the most important directory in the entire system. Subsequent directories are derived based on the root directory. More importantly, The root directory is related to booting, restoring, and system repair. Since system booting requires a specific environment, when an error occurs in the system, the root directory must also contain a program that can repair the file system. OK. Therefore, FHS stipulates that the partition size of the root directory should not be set too large. In fact, the smaller the better, to reduce the error rate.

FHS also stipulates that these directories should exist under the root directory.

/home directory

/home directory is the system default user home folder (home directory).

/boot directory

/boot directory contains static files required to start the operating system, such as the Linux kernel. These files are critical to system startup. Linux Kernel The commonly used file name is vmlinuz, but if you are using the grub2 boot program, the directory /boot/grub2 will also exist.

I just built the Linux, and the boot is as follows.

Technical answers to the definition and specifications of linux under /

Never delete the /boot directory, as doing so may cause the system to fail to start.

/dev directory

/dev The directory is some device nodes. These device nodes are devices in the Linux system or virtual devices provided by the kernel. These device nodes are also critical to the normal operation of the system. The devices in the /dev directory and subdirectories are character devices and block devices. Character devices are mouse, keyboard, and modem, and block devices are hard disks and floppy drives. Storing files in the /dev directory is equivalent to storing a device.

The more important files are

/dev/hda: the main device on the main IDE channel. When it comes to IDE/ATA hard disks, the main channel is the first and a channel that connects the second drive to the motherboard or interface card.

/dev/hdb: Slave device on the main IDE channel.

/dev/tty0: The first virtual console. Virtual console, also known as VC, also known as virtual terminal VT, is a conceptual combination of keyboard and monitor used for computer user interface.

/dev/tty1: The second virtual console.

/dev/sda: The first device on the primary SCSI and SATA channels.

/dev/lp0: The first parallel port.

The following is the directory under my Linux.

Technical answers to the definition and specifications of linux under /

/etc directory

/etc directory is reserved for the local configuration files of the computer. The main configuration files of the system are placed in this directory, such as account passwords, service start and stop. Generally speaking, Under this directory, general users only have read permissions, and only the root user has modification permissions (for permission issues, you can read the author's previous article and read this Linux permissions, which will make it clear!)

/etc Next The more important files are

/etc/modprobe.dKernel driver module

/etc/passwdStorage user password

/etc/fstab Storage mount information

/etc/issueThe content displayed when the storage system is started

Not required in the /etc directory To store binary files, binary files are best placed in /sbin and /bin. There are two important files in the

/etc directory, /etc/x11 are used to store X Window system configuration files, such as xorg.conf, /etc/opt This mainly stores configuration files related to third-party collaboration software/opt.

Technical answers to the definition and specifications of linux under /

/lib directory

There are many function libraries in the system, and the /lib directory is like a warehouse, which is used to store execution/bin Libraries required for binaries in and /sbin. These shared library images are particularly important for system boot and executing commands in the root file system.

Technical answers to the definition and specifications of linux under /

/media directory

media is the English word for media, which means /media can store removable media ( such as USB, DVD, CD-ROM, and Zip disks).

/mnt directory

If you want to temporarily mount some additional devices, you can put them in the /mnt directory. In fact, in the earliest times, /mnt was used the same as /media. , but later after /media was created, this directory was used for temporary mounting. The

/opt directory

/opt/ directory provides storage space for most application packages. Packages that place files in the /opt/ directory create a A directory with the same name as the package. In turn, this directory holds files that would otherwise be scattered throughout the file system, providing system administrators with an easy way to determine the role of each file in a specific package.

For example, if sample is the name of a specific package located in the /opt/ directory, then all files are placed in directories in the /opt/sample/ directory, such as /opt/sample/bin/ means binaries and /opt/sample/man/ for man pages.

Technical answers to the definition and specifications of linux under /

/proc directory

/proc The directory itself is a virtual filesystem, The data he places is in the memory, such as system core information, itinerary information, peripheral devices and network status, etc. Because the data in this directory is in memory, it does not occupy disk space.

The more important files in this directory include /proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/net/.

Technical answers to the definition and specifications of linux under /

/sbin directory

/sbin The directory stores executable files used by the root user. Executable files in /sbin are used at startup for system management and to perform system recovery operations. In addition to the binaries in /bin, /sbin also contains binaries needed to start, recover, and repair the system. The

/sbin directory contains arp, clock, halt, init, grub, ifconfig, route, shutdown, etc.

Technical answers to the definition and specifications of linux under /

/tmp directory

This directory stores some temporary files, which will be cleared when the system restarts.

Technical answers to the definition and specifications of linux under /

/sys directory

This directory is actually very similar to /proc. It is also a virtual file system that mainly records information related to the core and system hardware. This directory also takes up no disk space.

Technical answers to the definition and specifications of linux under /

/usr directory

/usr directory is a directory that needs to be discussed. Many readers mistakenly think that /usr is the abbreviation of user. In fact, usr is the abbreviation of Unix Software Resource. FHS recommends that software developers should reasonably place data in the subdirectory of this directory and do not create independent directories for the software themselves.

All system default software will be placed under /usr, so this directory is somewhat similar to C:\Windows\ C:\Program files\ The combination of these two directories, generally speaking , after the system is just installed, this directory will occupy more disk capacity. It is recommended that the subdirectory of /usr has the following contents

*/usr/bin/*Commands that general users can use are placed here. directory, starting from CentOS 7, the instructions under /usr/bin are exactly the same as the instructions under the /bin directory.

*/usr/lib/*Basically, it has the same function as /lib, so /lib is linked to this directory.

/usr/local The system administrator recommends that the software downloaded on this machine be installed in this directory for easy management.

/usr/sbin System commands that are not required for the normal operation of the system. The most common ones are the service commands of some network server software. However, the basic functions are similar to /sbin, so currently / sbin is linked to this directory.

/usr/share Shared file placement area, this directory also has these subdirectories /usr/share/man, /usr/share/doc, /usr/share/zoneinfo

/usr/games Game-related data placement location

/usr/include Header and include placement location for C/C and other programming languages , which is also directly linked.

/usr/src It is recommended to place the general source code here. src means source. As for the core source code, it is recommended to place it in the /usr/src/linux directory.

Technical answers to the definition and specifications of linux under /

/run directory

The early FHS stipulated that all information generated after the system is started should be placed in the /var/run directory. The new version FHS is standardized under /run.

/var directory

If /usr is a directory that will occupy a large disk capacity during installation, then /var will gradually occupy the disk after the system is running. Capacity directory. /var mainly includes cache, login files and directories generated by running certain software, including program files, such as MySQL database files, etc. Common directories are

/var/cache Application cache directory

/var/crash System error message

/var/log Log record

/var/run Process identification data

/var/tmp Temporary file directory

/var/lock File lock record

Technical answers to the definition and specifications of linux under /

/srv directory

srv can be seen as the abbreviation of service, which is what these services need to access after some network services are started. Data directory, common services such as WWW, FTP.

CentOS 7 is different from previous versions in terms of directory arrangement. This has been roughly described above. Here is a summary. The biggest difference is that many directories that should have been in the root directory will be replaced with all data. Move it to /usr, and then set the link, which includes

  • /bin -> /usr/bin
  • /sbin -> /usr/sbin
  • /lib -> /usr/lib
  • /lib64 -> /usr/lib64
  • /var/lock -> /run/ lock
  • /var/run -> /run

In order to make it easier for everyone to intuitively see what these directories do, I drew a picture by hand. The relationship between directories is very much like a tree, so this directory is also called a directory tree.

Technical answers to the definition and specifications of linux under /

This directory tree is already very clear, so there is nothing more to say.

Absolute paths and relative paths

Like other systems, paths in Linux are also divided into absolute paths (absolute) and relative paths (relative). The writing methods of these two are as follows:

  • The paths starting from the root directory are all absolute paths, such as /boot, /usr/local, etc. in the directory tree above.
  • The writing method relative to the current file path is relative path , for example.../var/log directory

One thing to note here is that the relative path is moved based on the relative position of your current path, for example, you are currently in In the /boot directory, you want to move to the /usr/src directory

Absolute path notation:/usr/src

Relative path notation:…/usr/src

There are two special directories that need to be noted here:

  • . : represents the current directory, you can also use ./ to represent
  • ... : represents the previous one The layer directory can also be represented by .../ Write all paths once, and just use.../ directly;
But in terms of the correctness of the file path, absolute paths are better than relative paths.

If you are writing a program to manage the system, be sure to use absolute paths, because absolute paths will find the specified file no matter where your file path is; and relative paths may exist if the file is moved. The file cannot be found.

Instructions related to the directory

Let’s talk about several instructions related to the directory

cd

cd is the abbreviation of change directory, this The command can switch the current working directory. There are four switching methods as follows

cd /路径名 # 表示切换到指定的工作目录cd ./ 		
# 表示切换到当前工作目录(无任何切换)cd .. 		
# 表示切换到当前工作目录的上一层目录cd ~ 			
# 表示返回到当前用户目录
Copy after login

Let’s demonstrate the operation of these four cd switching methods

Technical answers to the definition and specifications of linux under /

You can see So, we used cd /usr/local to switch to the command directory; used cd ./ without switching any directory (two seconds wasted); used cd... to switch to the upper level of the current working directory; used cd ~ to switch The default working directory of the currently logged in user is reached.

What needs to be noted here is cd ~. If you use cd directly, the switching effect is the same as cd ~, that is, "cd ~ == cd".

pwd

There is another instruction above which is pwd. This instruction is our most commonly used instruction. Its usage frequency is almost the same as cd, because a cd instruction is often followed by a pwd instruction. So you can see how important the pwd instruction is.

pwd is the abbreviation of Print Working Directory, which is an instruction to print out the current directory.

But pwd is not necessarily only used to display the current working path, it can also be used to display the file path in the specified working directory

Technical answers to the definition and specifications of linux under /

But this command seems like It's useless, because we already know the path in the working directory, so why print it out?

mkdir

mkdir is used to create a new directory. It is the abbreviation of make directory. Generally speaking, it will be followed by two parameters.

  • -m: Set the permissions of the file directly, without considering the creation permissions of the default file
  • -p: Create the directory recursively

The following is Operation of creating a file directory using mkdir

Technical answers to the definition and specifications of linux under /

As shown in the above figure, we created an empty directory called test1 in the /tmp file directory and printed out the current work Table of contents.

If you want to create a directory that you don’t want other users to access, you can use the following command

mkdir -m 711 test2
Copy after login

Technical answers to the definition and specifications of linux under /

listed by ls -ld in the above picture For the detailed information of the file directory, you can see that the first item in the detailed information is the file permissions.

Creating directories one by one is too troublesome. Now we want to create these directories quickly. For example, if we want to create a directory format of /test1/test2/test3/test4, we use the following code

Technical answers to the definition and specifications of linux under /

Linux will tell you that we cannot use this method of creation.

At this time, the -p parameter is needed. This parameter allows us to create directories recursively, as shown below

Technical answers to the definition and specifications of linux under /

Just use -p This method is not recommended because it is easy to make typos. . .

rmdir

rmdir is used to delete empty directories. Its use is very similar to mkdir. mkdir -p is used to create directories recursively. Similarly, rmdir -p can also delete directories recursively. As shown in the figure below

Technical answers to the definition and specifications of linux under /

It should be noted here that rmdir only deletes empty directories, which also means that if there is content in the directory, it cannot be deleted. So how to delete it? You can use rm -r directly to delete.

mv

Using mv can modify the name of the directory. For example, we created a directory called test. Later we felt that this directory could not reflect its owner and we wanted to change it. The name can be modified at this time using the mv command.

Technical answers to the definition and specifications of linux under /

After understanding the basic directory operations, let’s think about a question, why can we execute the ls command in various directories and it will be displayed? content? It stands to reason that shouldn't ls be available only in its storage path?

First of all, everyone needs to understand the concept of PATH. PATH is the environment variable. When we execute an instruction, the system will first follow the setting of PATH. Search for an executable file named ls under each PATH. If there are multiple executable files, the one searched will be executed first.

Original link: I only know these concepts after using Linux for so long. . .

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of Technical answers to the definition and specifications of linux under /. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template