Linux system directory tree structure and explanation

FHS standard

The abbreviation of Filesystem Hierarchy Standard (file system hierarchical standard). Most Linux versions adopt this file organization form, which is similar to the file directory of the c drive in the Windows operating system. FHS adopts the 树形结构organization file. FHS defines the purpose of each area in the system, the minimum required files and directories, and also provides exception handling and conflict handling.

FHS defines two layers of specifications. The first layer is /what file data should be placed in each of the following directories. For example, /etc should place configuration files, /bin and /sbin should place executable files, and so on. Because there are too many Linux developers, if everyone uses their own directory configuration method, it may cause many management problems. Can you imagine that after you enter an enterprise, the Linux directory configuration method you come into contact with is completely different from what you learned before? hard to imagine. Therefore, the so-called Filesystem Hierarchy Standard (FHS) was introduced later.

The second layer is defined for /usrthe /varsubdirectories of these two directories. For example, /var/log places system login files, /usr/share places shared data, and so on.

In other words, in fact, FHS only defines what data should be placed in the three-tier directory for the directory structure, namely:

  • /(root, root directory): related to the boot system.
  • /usr(UNIX software resource): Pertaining to software installation and execution.
  • /var(variable): related to the system operation process.

Linux directory tree

tree directory structure

insert image description here

Explanation of each directory

bin

bin is the abbreviation of Binaries (binary files). This directory stores the most frequently used commands, and places commands that can be operated in single-user mode maintenance mode. Commands under /bin can be used by root and general accounts. Such as: cat, chmod, chown, mkdir, cp, etc.

boot

Place the files used for booting, including liunx kernel files, boot menu and configuration files required for booting, including some connection files and image files.

/dev

dev is the abbreviation of Device (device). This directory stores Linux external devices and interface device files. The way to access devices and files in Linux is the same, as long as you access a file under this directory It is equivalent to accessing the device.

/etc

etc is the abbreviation of Etcetera (etc.), this directory is used to store all configuration files and subdirectories needed for system management.

Almost all the main configuration files of the system are placed in this directory, such as user accounts, passwords, various service start files, etc. The files in this directory can be viewed by ordinary users, but only the root user has the right to modify them. FHS recommends not to place executable files (binary) in this directory.

  • The more important files in this directory are:
    • /etc/inittab
    • /etc/init.d/
    • /etc/modprobe.conf
    • /etc/X11/: Various configuration files related to X Window are placed here, especially the XServer configuration file xorg.conf.
    • /etc/xinetd.d/: The configuration file directory of each service managed by the super daemon.
    • /etc/fstab
    • /etc/sysconfig
  • The important directories under this directory are:
    • /etc/init.d/: The default startup scripts for all services are placed here.
      For example, the command to enable or disable iptables is:

      /etc/init.d/iptables start  #启动
      /etc/init.d/iptables stop   #关闭
      

/home

The system defaults to the user's home folder. When creating an account, the user's home folder will be automatically generated under this directory. Generally, the directory name is named after the user's account, such as alice, bob, and eve in the above figure.

/root

The system administrator's home folder generally wants root's home folder and root directory to be placed in the same partition.

/lib

Lib is the abbreviation of Library (library), which places the function library used when the system is turned on and the most basic dynamic link shared library of the system. Almost all applications need to use these shared libraries. Its function is similar to the DLL file in Windows, and the function library that will be called by the command in /binor below is also included./sbin/lib

/lib/modules/This directory places the kernel-related drivers.

/media

/mediaPlaced below are removable devices. The Linux system will automatically recognize some devices, such as U disk, CD-ROM, etc. After recognition, Linux will mount the recognized devices to this directory.

/mmt

Similar to /mediathe function, the system provides this directory to allow users to temporarily mount other file systems. We can mount the CD-ROM /mnt/on , and then enter this directory to view the contents of the CD-ROM.

/opt

opt is the abbreviation of optional (optional), which is the directory for additional installation of third-party software on the host. For example, if you install an ORACLE database, you can put it in this directory. The default is empty.

/proc

proc is the abbreviation of Processes (process), /proc is a pseudo file system (that is, virtual file system), which stores a series of special files of the current kernel running state, this directory is a virtual directory, it is the system memory Mapping, we can get system information by directly accessing this directory.

For example, to view information about a process:ll /proc/pid

The content of this directory is not on the hard disk but in the memory. We can also directly modify some files in it. For example, the following command can be used to block the ping command of the host so that others cannot ping your machine:
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

/run

It is a temporary file system that stores information since the system was started. When the system restarts, the files in this directory should be deleted or cleared. If you have a /var/run directory on your system, it should point to run.

/sbin

s is the meaning of Super User, which is the abbreviation of Superuser Binaries (superuser binary files). The system management program used by the system administrator is stored here. The commands in the directory can only be used by root users, and ordinary users only have query permissions /sbin. /sbinContains the commands required for booting, repairing, and restoring the system.

As for server software program commands, they are generally placed in /usr/sbin/.

The commands generated by the third-party software installed on this machine are placed in /usr/local/sbin/.

/tmp

A place where general users or programs that are being executed temporarily place files. This directory is accessible by anyone and needs to be cleaned up periodically.

Note: The directories that cannot be separated from the root directory include: /etc, /bin, /sbin, /dev, /libthese five directories.

/sys

This is a big change in the Linux2.6 kernel. A new file system sysfs in the 2.6 kernel is installed in this directory.

The sysfs file system integrates the information of the following three file systems:

  • proc file system for process information,
  • devfs file system for devices
  • The devpts filesystem for pseudo-terminals.

The file system is a visual reflection of the kernel device tree.
When a kernel object is created, corresponding files and directories are also created in the kernel object subsystem.

/selinux

This directory is a special directory for Redhat/CentOS. Selinux is a security mechanism, similar to the Windows firewall, but this mechanism is more complicated. This directory is for storing selinux-related files.

/lost+found

This directory is usually empty. When the system is shut down illegally, some files are stored here.

/srv

After some network services are started, the directories that these services need to read data. Common services such as WWW, FTP, etc., the webpage data required by WWW services are placed inside /srv/www/.

/usr

Many applications and files of the user are placed in this directory, which is similar to the program files directory under Windows.

/usrThe subdirectories contained under:

  • /usr/lib/: Contains function libraries, object files, and execution files or scripts that are not commonly used by ordinary users. Note that the file name may also be /usr/lib64.
  • /usr/bin/: Most users can use commands to put here, pay attention to the difference with /bin (whether it is related to the boot process).
  • /usr/sbin/: It is not a system command required for the normal operation of the system.
  • /usr/src/: The default directory where the kernel source code is placed.
  • /usr/local/: The third-party software installation location.
  • /usr/share/: The place where shared files are placed, and various help document directories are also under this.
  • /usr/include/: C/C++ and other programming language header files and include files are placed. When using tarball method (*.tar.gz method to install software) to install some data, many files inside will be used.
  • /usr/X11R6/:X Window system important data prevention directory.

/var

Store frequently modified data, such as log files of program operation (under the /var/log directory).

/varThe subdirectories contained under:

  • /var/cache/: Some temporary files generated during the running of the application.
  • /var/lib/: During the running of the program itself, the data files that need to be used are placed here.
  • /var/lock/: Certain devices or file resources can only be used by one application program, and this file is to lock the file to ensure single software use.
  • /var/log/: The directory where the registration file is placed.
  • /var/mail/: Personal mailbox directory, but this directory is also placed in /var/spool/mail/the directory, and the two directories are connected files to each other.
  • /var/run/: After some programs or services are started, their PIDs will be placed in this directory.
  • /var/spool/: This directory places some queue data.

Reference: Cainiao Tutorial
Reference: Directory tree structure under Linux system

Guess you like

Origin blog.csdn.net/weixin_43702146/article/details/130528076