LINUX directory-FHS standard

Preface: This blog post is based on Centos7

Linux directory configuration basis-FHS

FHS is a standard. Their main purpose is to let users know which directory the installed software is usually stored in.

Four types

  • Shareable: It can be shared to the directories used by other systems for mounting, so data including executable files and user emails can be shared with other hosts on the network for mounting.
  • Unshareable: Device files or socket files related to programs running on your own machine are not suitable for sharing with other hosts because they are related to your own machine.
  • Unchanged: Some data does not change frequently, such as function libraries, file descriptions, and host service configuration files managed by the system administrator.
  • Variable: data that is frequently modified, such as log files, newsgroups that can be received by general user groups, etc.

Three directory structures

  • /: (root, root directory): related to starting the system.
  • /usr: (unix softwore resource): related to software installation/execution.
  • /var: (variable) is related to the running process of the system.

The meaning and content of the root directory (/)

Not only are all directories derived from the root directory, but the root directory is also related to operations such as startup, restore, and system repair . When an error occurs in the system, the root directory must contain a program that can repair the file system. Therefore, FHS recommends that the partition where the root directory (/) is located is as small as possible, and the software installed by the application should not be placed in the root directory. In the same partition, keep the root directory as small as possible, so that not only the performance is good, but the file system where the root directory is located is not prone to problems .

Subdirectories under the root directory

Even if there is no physical directory below, at least there must be a link directory.
Insert picture description here

  • /bin: Placed under /bin are commands that can be used in single maintenance mode . The commands under /bin can be used by root and general users.

    Mainly include cat, chmod, chown, date, mv, mkdir, cp, bash, etc.

  • /boot: This directory mainly stores the files that will be used during startup , including Linux kernel files and startup options, and configuration files required for startup.

    The commonly used file name of the Linux kernel is vmlinuz.

  • /dev: On Linux systems, any device and interface device exist in this directory in the form of files . You can read and write a device by reading and writing a file in the directory.

    The more important files are: /dev/null, /dev/zero, /dev/tty, /dev/loop*, /dev/sd*.

  • /etc: This directory mainly stores the main configuration files of the system , such as personnel account and password files, and startup files of various services. Generally, this file is read-only by ordinary users and can only be modified by the root user. FHS recommends not to put executable files in this directory.

    The more important files are: /etc/modprobe.d/, /etc/passwd, /etc/fstab, /etc/issue.
    In addition, there is another important directory that is best under the /etc directory: /etc/opt (necessary): This directory stores the relevant configuration files of third-party auxiliary software-/opt.

  • /lib: Place the function library that will be used at startup, as well as the function library that the commands under /bin or /sbin need to call . The function library can be understood as a plug-in, some commands require these plug-ins to successfully complete the program execution.

    /lib/modules/ must be under /lib, it stores mainly replaceable kernel-related modules (drivers).

  • /media: Deletable devices are placed, including floppy disks, CDs, DVDs and other devices that are temporarily mounted here .

    Commonly used file names are: /media/floppy, /media/cdrom, etc.

  • /mnt: In the early days, this directory was the function of /media, after having /media, this directory was used for temporary mounting.

  • /opt: The directory for third-party auxiliary software . For example, the desktop management system KDE is an independent software. If it is installed in Linux, it is recommended to put it here.

  • /run: The information generated by system startup is placed here. Because /run can be simulated with memory, the performance is better.

  • /sbin: Stored in this directory are the commands needed during the startup process, including the commands needed to start, repair, and restore the system .

    Common commands include: fdisk, fsck, ifconfig, mkfs, etc.

  • /srv: Store the data required by some network services after they are started. Common ones are WWW, FTP, etc. The web page data required by WWW can be placed in /srv/www.

  • /tmp: A place to temporarily store files for some users or programs being executed. Anyone can access this directory, so it should be cleaned up regularly.

  • /home: The default user home directory of the system . When you add a general user, the default user home directory will be standardized here.

    The more important home directories have two codes:

    • ~: represents the home directory of the current user.
    • ~dmtsai: represents the home directory of dmtsai.
  • /lib<qual>: Used to store binary function libraries in different formats from /lib, such as /lib64 that supports 64-bit systems.

  • /proc: This directory is a virtual filesystem (virtual filesystem). The data it stores is in memory, so it does not occupy hard disk space, such as system kernel, process information, status of external devices, and network status.

    More important files: /proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net*, etc.

  • /sys: It is also a virtual file system, which mainly records the content related to the kernel and system hardware information. Including the currently loaded kernel module and the hardware device information detected by the kernel.

  • /usr: The second-level FHS settings.

  • /var: Layer 2 FHS settings.

The meaning and content of /usr

usr is the abbreviation of Unix Software Resourse. The data stored in /usr is sharable and unchangeable. It is the directory where the Unix operating system software resources are placed , not user data.
The recommended subdirectories of /usr are as follows:
Insert picture description here

  • /usr/bin/: The commands that general users can use are placed here. At present, Centos7 has stored all user commands here, and the /bin directory is linked to this by means of link files, which means that /bin and /usr/bin are the same.

  • /usr/lib/: Basically the same function as /lib, so /lib is linked to this directory.

  • /usr/local/: The system administrator installs the downloaded software on this machine (not provided by the release version by default) and will be placed in this directory for easy management. Therefore /usr/local has a similar directory structure to /usr.
    Insert picture description here

  • /usr/sbin/: Commands that are not required for the normal operation of the system, the most common is the service command (deamon) of some network server software . The basic function is also similar to /sbin, so currently /sbin is linked to this directory.

  • /usr/share/: Mainly store read-only data files , of course, including shared files. The data placed in this directory is almost readable data regardless of the hardware architecture, because almost all are text files.

    Common directories are as follows:

    • /usr/share/man: online help file
    • /usr/share/doc: software documentation
    • /usr/share/zoneinfo: Time zone file related to time zone
  • /usr/games/: Data related to games is placed here.

  • /usr/include/: where the header and include files of programming languages ​​such as c/c++ are placed.

  • /usr/libexec/: Some executable files or scripts that are not commonly used by general users will be placed here.

  • /usr/lib <qual >/: Same function as /lib <qual >/, now /lib <qual >/ is linked to this directory.

  • /usr/src: The general source code is placed here. For example, the source code of the kernel file is recommended to be placed in the /usr/src/Linux/ directory.

The meaning and content of /var

/var is a directory that gradually occupies hard disk capacity after the system is running. Because the /var directory is mainly for files that change frequently, including caches, log files, and files generated when certain software is running, including program files (lock file, run file), or, for example, MySQL database document.
Common subdirectories are:

  • /var/cache/: Store some caches generated during the running of the application itself.

  • /var/lib/: The directory where the data files that need to be used during the execution of the program itself are placed. Each software in this directory should have its own directory. For example, /var/lib/mysql, var/lib/rpm.

  • /var/lock/: Some devices or file resources can only be used by one application at a time, so it is necessary to lock the device to ensure that the device can only be used by a single software at a time.

  • /var/log/ (important!): is the directory where log files are stored.

    The more important documents are:

    • /var/log/messages, /var/log/wtmp (record login information), etc.
  • /var/mail/: The directory where personal e-mails are placed. This directory and /var/spool/mail/ are mutually linked files.

  • /var/run/: After some programs or services are started, their PIDs are placed in this directory. This directory is linked to the /run/ directory.

  • /var/spool/: This directory usually puts some queue data. The so-called queue is the data queued for use by other programs. These data are usually deleted after being used.
    For example, a new mail received by the system will be placed in /var/spool/mail/, but after the user accepts it, the envelope will be deleted in principle.

Summarize the link settings that appear in the above directories

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

Guess you like

Origin blog.csdn.net/qq_40741808/article/details/107005418