Linux Directory Specifications and Meanings (RPM)

Source: Internet
Author: User

Linux Directory Configuration

After learning about the types and attributes of each file, and how to change the information about file properties/permissions, let's see why every Linux distributions their profiles, executable files, and every directory that they put in. It turned out to be a standard basis.

Linux directory configuration based on--FHS

Because there are so many communities/companies and individuals that use Linux to develop products or distributions, if everyone uses their own ideas to configure a directory for file placement, it can be a lot of management trouble. Can you imagine that after you entered a business, the Linux directory configuration method that you came into contact with was completely different from what you learned before? Hard to imagine ~ So, then there is the so-called Filesystem Hierarchy Standard (FHS) standards of the oven!

According to FHS's official paper, the main purpose of the to let users know that the installed software is usually placed in that directory, so they want independent software developers, operating system creators, and users who want to maintain the system, are able to follow the FHS standard. In other words, the focus of FHS is to standardize what data should be placed in each particular directory. This is a lot of benefit because the Linux operating system is able to develop the unique style that developers want under the existing landscape (directory architecture unchanged).

In fact, FHS is based on the past experience has been continuously revised, FHS based on the use of the file system and whether or not to allow users to change randomly, and the directory is defined as four interactive forms, in the form of a bit like the bottom:

  Shareable (shareable) Non-shareable (unshareable)
Constant (Static) /usr (software placement) /etc (config file)
  /OPT (third party collaboration software) /boot (boot and core file)
Variable (variable) /var/mail (User mail box) /var/run (program-related)
  /var/spool/news (News Group) /var/lock (program-related)

The table above is a list of representative directories, the data placed under the directory will be discussed below, here first skip the talk. What we want to know is, what are those four types?

    • Shareable: can be shared with other systems to mount the use of the directory, so including the execution of files and users of the mail and other data, is able to share to other hosts on the network mounted directory;

    • Not to be shared: The device file or socket file related to the program is not suitable for sharing with other hosts because it is only related to its own machine.

    • Constant: Some of the data is not constantly changing, along with distribution without change. For example, a function library, file description file, the system administrator manages the host service configuration file and so on;

    • Variable: frequently changing data, such as log-in files, newsgroups that are normally accepted by users, and so on.

In fact, FHS only defines what data should be placed under the three-level directory for the directory tree schema, which is the definition of the three directories below:

    • /(Root, root directory): related to boot system;
    • /usr (Unix software Resource): Related to Software installation/execution;
    • /var (variable): related to the system operation process.

Why do you define these three-tier catalogs? Actually, it's meaningful, oh! The directories that should be placed under each level are also specified. Since we have not yet introduced the complete Linux system, you may not be able to read the introduction below! It doesn't matter, first there is a concept, wait until you have finished reading the basic article, then re-read the basic article again! Then you'll be enlightened!

    • The meaning and content of the root directory (/):

The root directory is the most important directory for the entire system, because not only are all directories derived from the root directory, but the root directory is also associated with actions such as boot/restore/system repair. Because the system requires specific power-on software, core files, power-on required programs, function libraries and other file data, if the system error occurs, the root directory must also include the ability to repair the file system. Because the root directory is so important, so in terms of FHS requirements, he wants the root directory is not placed in a very large partition slot, because the larger the partition slot you will put more data, so that the root of the partition slot there may be more error opportunities.

Therefore FHS Standard Recommendation: The root directory (/) where the partition should be smaller, the better, and the software installed by the application should not be placed in the same partition with the root directory, keep the root directory smaller the better. This is not only good performance, the root directory is located in the file system is less prone to problems.

Given the above explanation, FHS defines that the root directory (/) should have the following directories at the bottom:

The main configuration files of the
Directory File contents should be placed
/bin The system has a lot of directories for executing files, but/bin is more special. Because the /bin is placed in the single maintenance mode can also be operated instructions. The commands under/bin can be used by root and general account, mainly: Cat, chmod, chown, date, MV, mkdir, CP, Bash and so on.
/boot This directory is mainly used to put the files on the boot, including the Linux core files and boot menu and boot required configuration files and so on. Linux kernel commonly used file name: Vmlinuz, if you are using grub this boot manager, there will be/boot/grub/this directory Oh!
/dev On a Linux system, any device or interface device is present in this directory in the form of a file. All you have to do is access a device by accessing one of the files under the directory- /dev/null,/dev/zero,/dev/tty,/dev/lp*,/dev/hd*,/dev/sd*, etc.
/etc system are placed almost in this directory, such as the person's account password file, the start of various services, and so on. In general, the file attributes in this directory are accessible to the general user, but only root has the power to modify it. FHS it is recommended that you do not place executable files (binary) in this directory. The more important documents are:  /etc/inittab,/etc/init.d/,/etc/modprobe.conf,/etc/x11/,/etc/fstab,/ etc/sysconfig/  and so on. In addition, the following important directories are:
  • /etc/init.d/: Preset startup script for all services is put here, For example, to start or close iptables: "/etc/init.d/iptables start", "/etc/init.d/iptables stop"
  • /etc/xinetd.d/: This is the configuration file directory of the various services that are called Super Daemon Management.
  • /etc/x11/: The various configuration files related to x Window are here, especially xorg.conf this x Server configuration file.
/home This is the system default user home directory (home directory). When you add a general user account, the default home directory will be standardized here. More importantly, the home directory has two code names OH:
~: Represents the current user's home directory, and
~dmtsai: It represents Dmtsai's home directory!
/lib The system has a much more functional library, and /lib places a library of functions that will be used at boot time, as well as a function library that the instructions under/bin or/sbin will call. What is a function library? You can think of him as a "plug-in", some instructions must have these "plug-in" to be able to successfully complete the implementation of the program meaning. It is especially important to /lib/modules/this directory, because the directory will place the core related modules (drivers) Oh!
/media Media is the "medium" of English, as the name implies, this /media is placed under the removable device! Such devices as floppy disks, CDs, DVDs and so on are temporarily mounted here. Common file names are:/media/floppy,/media/cdrom, and so on.
/mnt If you want to temporarily mount some additional devices, it is generally recommended that you place them in this directory. In ancient times, the use of this directory is the same as/media! Just after the/media, this directory is used for temporary loading.
/opt This is the directory for third-party software placement. What is third party collaboration software? For example, the KDE desktop Management system is a standalone program, but it can be installed on a Linux system, so KDE software is recommended to be placed in this directory. Also, if you want to install additional software on your own (not provided by the original distribution), you will be able to install your software here as well. However, in the previous Linux system, we are still accustomed to place in the/usr/local directory!
/root The home directory of the system administrator (root). The reason for this is that if you go into single-player maintenance mode and only mount the root directory, that directory will be able to have the root home directory, so we would like Root home directory and root directory in the same partition slot.
/sbin Linux has a lot of instructions to set up the system environment, these instructions only root can be used to "set up" system, the other users can only be used to "query" only. placed under the/sbin for the boot process required, which includes the boot, repair, restore the system required instructions. As for some server software programs, it is generally placed in the/usr/sbin/. The system binaries generated by the natively installed software are placed in the/usr/local/sbin/. Common directives include: fdisk, fsck, Ifconfig, Init, MKFS, and so on.
/srv SRV can be considered an abbreviation for "service", which is the data directory to be used by some network services after they are started. Common services such as WWW, FTP and so on. For example, the Web page data required by the WWW server can be placed inside the/srv/www/.
/tmp This is where the general user or the executing program temporarily places the file. This directory is accessible to anyone, so you need to clean it up regularly. Of course, important data can not be placed in this directory Ah! Because FHS even suggested that when the boot, you should be the/TMP data are deleted YO!

In fact FHS the standard defined for the root directory is just the top, but there are a lot of directories underneath our Linux that you need to know about. Below are a few of the most important directories in Linux:

Directory File contents should be placed
/lost+found This directory is a directory that is generated using the standard EXT2/EXT3 file system format, in order to place some missing fragments into this directory when the file system has an error. This directory usually exists at the top level of the splitter slot, for example if you add a hard disk to/disk, and the system will automatically generate a directory like "/disk/lost+found"
/proc This directory itself is a "virtual file system (FileSystem)" Oh! The data he places are in memory, such as the system core, the trip information (process), the state of the peripheral device, and the network status. Because the data in this directory is in memory, so it does not occupy any hard disk space Ah! More important documents such as:/proc/cpuinfo,/PROC/DMA,/proc/interrupts,/proc/ioports,/proc/net/* and so on.
/sys This directory is very similar to/proc, but also a virtual file system, which is also the key to record the information related to the core. Including the core modules currently loaded and the core detected hardware device information, and so on. This directory also does not occupy the hard drive capacity Oh!

In addition to the contents of these directories, it is also important to note that because the root directory and boot-related, only the root directory will be mounted during the boot process, the other slots are the boot after the completion of the continuous loading behavior. Because of this, so the root directory with the boot process-related directory, it is not able to be placed with the root directory of different slots to go! Which directories cannot be separated from the root directory? There are these below:

    • /etc: Configuration file
    • /bin: Important Execution file
    • /dev: Required device files
    • /lib: Function libraries required for execution of files and modules required by the core
    • /sbin: Important System Execution files

These five directories must not be separated from the root directory in different partition slots! Please carry it down! All right, let's talk about the root directory, and then we'll talk about/usr and/var! Let's look at/usr for some things:

    • The meaning and content of/usr:

According to the basic definition of FHS, the data placed in/USR is shareable and immutable (shareable, static), if you know how to mount the partition slot through the network (for example, the NFS server that is discussed in the server), then/ USR can really share it with other hosts in the local area network.

Many readers will misunderstand/usr as user abbreviation, in fact, USR is the abbreviation of UNIX software resource, that is, "Unix Operating system software resources" placed in the directory, rather than the user's data! Pay attention to this point. FHS recommends that all software developers should place their data reasonably in the sub-directory under this directory, rather than building the software's own separate directory.

Because all system default software (software provided by distribution Publishers) is placed under/usr, this directory is somewhat similar to the "C:\Windows\ + C:\Program files\" combination of Windows systems, When the system has just been installed, this directory will occupy the most hard disk capacity. In general, the sub-directory of/USR suggests the following:

Directory File contents should be placed
/usr/x11r6/ The directory that was placed for the X Window system's important data is named X11R6 because the final x version is the 11th version, and the 6th release of the version is intended.
/usr/bin/ Most of the users can use the instructions are put here! Please note the difference between him and/bin. (whether it is related to the boot process)
/usr/include/ The file header (header) of the program language such as C + + and the Include file (include) place, when we install the software in Tarball Way (*.tar.gz way), we will use a lot of contained files inside!
/usr/lib/ A function library that contains the application software, the object file, and an executable file or script that is not commonly used by the user. Some software will provide some special instructions for the server settings, these instructions are not often operated by the system administrator, it will be placed in this directory. It is important to note that if you are using a x86_64 Linux system, there may be/usr/lib64/directories to produce Oh!
/usr/local/ The system administrator installs its own downloaded software (non-distribution default provider) on the machine, and recommends installing to this directory, which is easier to manage. For example, your distribution provides older software, you want to install newer software but do not want to remove the old version, you can install the new version of the software in the/usr/local/directory, can be different from the previous version of the software! You can go to the/usr/local yourself to see, the directory is also has bin, etc, include, Lib ... The Secondary catalogue Oh!
/usr/sbin/ System directives that are required for non-system normal operation. The most common is the service instructions for some Web server Software (daemon)!
/usr/share/ Where the shared files are placed, the data placed in this directory is almost always readable by the hardware architecture, because it is almost a text file! These secondary directories are common in this directory:
  • /usr/share/man: Online Help file
  • /usr/share/doc: Software Miscellaneous File description
  • /usr/share/zoneinfo: Time zone files associated with the time zone
/usr/src/ The general source code is suggested to be placed here, SRC has the meaning of source. The core source code is recommended to be placed in the/usr/src/linux/directory.

    • The meaning and content of/var:

If/usr is a directory that occupies a larger hard disk capacity during installation,/var is the directory that will gradually take up the capacity of the hard disk after the system is operational. Because the/var directory is primarily for files with normal changes, including cache, login file (log file), and files generated by some software operations, including program files (lock file, run file), or files such as MySQL database. Common sub-directories are:

Directory File contents should be placed
/var/cache/ Some temporary archives that will occur during the operation of the application itself;
/var/lib/ The program itself executes the process that needs to be used to place the data file in the directory. In this directory the respective software should have its own directory. For example, the MySQL database is placed in the/var/lib/mysql/and the RPM database is put into/var/lib/rpm!
/var/lock/ Some devices or file resources can only be used by one application at a time, if there are two programs using the device, there may be some wrong situation, so it is necessary to lock the device (lock), to ensure that the device will only be used for a single software. For example, the recorder is burning a disc, do you think, there will be two people at the same time using a burner burning tablets? If two people were recording at the same time, whose data was written by that film? So when the first person is burning the burner is locked and the second person has to be unlocked (that is, the previous person ran out) to continue using it.
/var/log/ Important To Not! This is the directory where the login files are placed! There are more important documents such as/var/log/messages,/var/log/wtmp (log in information) and so on.
/var/mail/ The directory where personal e-mail is placed, but this directory is also placed in the/var/spool/mail/directory! Usually the two directories are linked files for each other!
/var/run/ After some programs or services are started, their PID will be placed in this directory. As for the meaning of PID, we will refer to it in subsequent chapters.
/var/spool/ This directory usually places some queue data, so-called "queues" are queued to wait for other programs to use the data! This data is usually deleted after it is used. For example, the system receives a new letter that will be placed in the/var/spool/mail/, but the letter will be deleted in principle after the user has received the letter. If the letter is not sent out temporarily, it will be put into the/var/spool/mqueue/, and then deleted after being sent out. If it is work scheduling data (crontab), it will be placed in the/var/spool/cron/directory!

It is recommended that after you have read the entire basic article, you can challenge FHS official English document (refer to this chapter for reference), I believe it will give you a more in-depth understanding of the Linux operating system directory!

    • For FHS, the similarities and differences of each family distributions

Since FHS only defines the file or directory data that should be placed on the top (/) and sub-level (/usr,/var) directory content, it can be configured with the developer on its own at the other sub-directory levels. For example, the CentOS network settings data is placed in the/etc/sysconfig/network-scripts/directory, but SuSE is to place the network in the/etc/sysconfig/network/directory, the directory name is different! But just remember the general FHS standard, the difference is actually limited!

catalog tree (directory trees)

In addition, under Linux, all files and directories are started by the root directory! That's the source of all the directories and files ~ and then one branch down, a bit like a twig ~ so we also call this directory configuration: "Directory tree" What is the directory tree feature? His main features are:

    • The starting point of the directory tree is the root directory (/, root);
    • Each directory can not only use the local-side partition file system, but also use the filesystem on the network. For example, you can use the Network File System (NFS) server to mount a specific directory, and so on.
    • Each file name (including the full path) in this directory tree is unique.

OK, after talking about the standard of FHS, actually take a look at what the CentOS will look like under the root directory! We can issue the following instructions to query:

[[email protected] ~]# ls-l/drwxr-xr-x 2 root root 4096 Sep 5 12:34 bindrwxr-xr-x 4 root root 1024x768 Sep 4 18 : bootdrwxr-xr-x root root 4320 Sep 12:10 devdrwxr-xr-x root root 12288 Sep 12:10 etcdrwxr-xr-x 4 root Root 4096 Sep 5 14:08 homedrwxr-xr-x root root 4096 Sep 5 12:12 libdrwx------2 root root 16384 Sep 5 01:49 los T+founddrwxr-xr-x 2 root root 4096 Mar mediadrwxr-xr-x 2 root root 0 Sep 12:09 miscdrwxr-xr-x 2 Roo T root 4096 Mar mntdrwxr-xr-x 2 root root 0 Sep 12:09 netdrwxr-xr-x 2 root root 4096 mar Tdr-xr-xr-x root root 0 Sep procdrwxr-x---4 root root 4096 Sep 8 14:06 rootdrwxr-xr-x 2 root root 12288 Sep 5 12:33 sbindrwxr-xr-x 4 root root 0 Sep selinuxdrwxr-xr-x 2 root root 4096 Mar Rwxr-xr-x root root 0 Sep sysdrwxrwxrwt 6 root root 4096 Sep 12:10 tmpdrwxr-xr-x root root 409 6 Sep 4 18:00 usrdrwxr-Xr-x root root 4096 Sep 4 18:19 var 

If we display the entire directory tree as an icon, and the more important file data is listed, then the directory tree schema is a bit like this: The table above the special should be/selinux this directory, the contents of this directory data is also in memory information, The same does not occupy any hard disk capacity. This/selinux is the executable directory for Secure Enhance Linux (SELinux), and SELinux is one of the important plug-ins of the Linux core, which he can use as a control for detailed permissions, primarily to restrict access to programs (especially network programs). About SELinux We will continue to introduce in the following chapters!

Directory tree Schema

Brother Bird only on the list of simple explanations, look at the good, detailed explanations please go back to the table just explained to see Oh! According to the definition of FHS, you'd better be able to separate/Var, so there is some security protection for the data of the system! Because at least Var is dead, your root directory will still be alive! Can also enter the rescue mode Ah!

absolute path vs. relative path

In addition to special attention to the FHS directory configuration, in the filename section we also have to pay special attention to Oh! The so-called path (path) can be defined as an absolute path (absolute) and a relative path (relative), depending on how the file name is written. The two filenames/paths are written according to this:

    • Absolute path: The name of a file or directory, such as/HOME/DMTSAI/.BASHRC, that is started by the root directory (/).
    • Relative path: The name of the file in relation to the current path. such as./home/dmtsai or, and so on. Anyway, the beginning is not/is a relative path to the wording

And you have to understand that the relative path is expressed as "the relative position of your current path." For example, if you are currently in the/home directory, what can you do if you want to enter the/var/log directory?

    1. Cd/var/log (absolute)
    2. Cd.. /var/log (relative)

Because you are under/home, so go back to the previous layer (. /) to move to/var! Pay particular attention to these two special directories:

    • . : Represents the current directory, or it can be used.
    • .. : Represents the previous level of the directory, or you can ... /to represent.

This one. And.. The catalog concept is important and you will often see CDs. Or./command, such as the order of instructions, is to represent the previous layer and the current directory working status Oh! It's important!

Transferred from:

Linux Directory Specifications and Meanings (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.