Linux directory Structure

Source: Internet
Author: User

For every Linux learner, learn about the directory structure of a Linux file system, is a very important step to learn Linux., in-depth understanding of the Linux file directory structure of the standard and detailed features of each directory, for us to use a good Linux system is essential, we will begin to understand the Linux directory structure of the relevant knowledge.

When using Linux, if you go through ls–l/you will find that there are many directories, such as etc, USR, var, bin ... And so on, and in these directories, we go inside and see that there are also a lot of directories or files. The file system looks like a tree structure under Linux, so we can refer to the structure of the file system as a tree-shaped structure.

The file system is used to organize and arrange file access, so she is visible, in Linux, we can use LS and other tools to view its structure, in the Linux system, we see the tree structure, such as the operating system installed in a file system, he is represented by the/start of the tree structure. At the top of the Linux filesystem is/, we call the Linux root, which is the filesystem of the Linux operating system. The Linux file System entry is/, all directories, files, devices are in/below,/is the Linux file system Organizer, is also the most superior leader.

Since Linux is open source, major companies and groups are programmed to do their own work according to the core code of Linux. This causes the directory under the root to be different. This creates a PC where individuals cannot use other people's Linux systems. Because you don't even know the basic configuration, where the files are ... This creates confusion. This is why the FHS (Filesystem Hierarchy Standard) Institution was born. The agency is a voluntary group of Linux enthusiasts, mainly to do some basic requirements for Linux, not the operator to replace a host becomes the Linux ' illiterate '.

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)

Four-Medium type:

1. Available for sharing:

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;

2. Non-shareable:

The device files that operate on the machine or the socket files related to the program are not suitable for sharing with other hosts because they are only related to their own machines.

3. Unchanged:

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

4. Subject to change:

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.

I. 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, in terms of FHS requirements, he wants the root directory not to be placed in a very large partition, because the larger the partition you will put more data, so that the root directory of the partition there may be more error opportunities.

Therefore, the FHS standard recommendation: The root directory (/) should be the smaller the partition should be 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 as small as possible. This is not only good performance, the root directory is located in the file system is less prone to problems. To be blunt, the root directory is the same as the C disk of Windows.

For these reasons, FHS that the root directory (/) should contain the following subdirectories:


File contents should be placed


The system has many directories to place the execution files, but/bin is more special. Because the/bin is placed in the single maintenance mode can also be operated instructions. The instructions under/bin can be used by root and general account, mainly: cat,chmod (Modify permission), Chown, date, MV, mkdir, CP, bash, etc. commonly used instructions.


The main place to boot will use the file, 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 also be/boot/grub/this directory.


On Linux systems, any device and peripherals are in this directory in the form of archives. Simply by accessing a file in this directory, you are accessing a device. More important files are/dev/null,/dev/zero,/dev/tty,/dev/lp*,/dev/hd*,/dev/sd*, etc.


Most of the system configuration files are placed 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 does not recommend placing executable files (binary) in this directory. The more important files are:/etc/inittab,/etc/init.d/,/etc/modprobe.conf,/etc/x11/,/etc/fstab,/etc/sysconfig/and so on. In addition, the following important directory is:/etc/init.d/: All the services of the preset start script is placed here, for example to start or close iptables:/etc/init.d/iptables start,/etc/init.d/ Iptables stop

/etc/xinetd.d/: This is the so-called Super Daemon Management of the various service profiles directory.

/ETC/X11/: The various profiles associated with X window are here, especially for the two X server profiles of xorg.conf or Xf86config.


This is the system preset user home directory (home directory). When you add a general user account, the default user home directory will be standardized here. More importantly, the home directory has two types of code:
~: Represents the home directory of the current consumer, and ~guest: Represents the home directory where the user name is guest.


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-ins in order to successfully complete the implementation of the program meaning. It is particularly important to/lib/modules/this directory, as it will place the core-related modules (drivers).


Media is the medium of the English language, as the name implies, this/media is placed under the removable device. The devices, including soft discs, CDs, DVDs and so on, are temporarily mounted here. Common file names are:/media/floppy,/media/cdrom, and so on.


If you want to temporarily mount some additional devices, it is generally recommended that you place them in this directory. In ancient times, this catalogue was used in the same way as/media. Just after the/media, this directory is used for temporary loading.


This is a directory for third-party software placement. What is a third-party collaboration software? For example, the KDE desktop Management system is a standalone project, 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 previous Linux systems, we were accustomed to placing them under the/usr/local directory.


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 to be placed in the same partition.


Linux has a lot of instructions to set up the system environment, these instructions only root can be used to set up the system, the other users can only be used to query. 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, they are generally placed in/usr/sbin/. System binary, which is generated by the natively installed software, is placed in the/usr/local/sbin/. Common directives include: fdisk, fsck, Ifconfig, Init, MKFS, and so on.


SRV can be regarded as the abbreviation of a service, which is a directory of data to be used by these services after the startup of some network services. 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/. Oh, it seems that the usual code we write should be put here.


This is where the general user or an executing program temporarily places the file. This directory is accessible to anyone, so you need to clean it up regularly. Of course, important information can not be placed in this directory AH. Because FHS even suggested that when the boot, you should be the/TMP data are deleted.

In fact FHS the criteria defined for the root directory are limited to the table above, but there are still some directories that we need to understand, as follows:


Should place file contents


This directory is using standard ext2 /EXT3 file system format will be generated by a directory, the purpose is that when the file system error, some missing fragments placed in this directory.   This directory usually exists at the top of the splitter slot, for example, if you add a hard drive to/disk, the system will automatically generate a directory like this/disk/lost+found


This directory itself is a virtual file system (Virtual filesystem) Oh.   The information he placed is in memory, such as system core, trip information (process), peripheral device status and network status, etc. Because the data in this directory is in memory (memory), so it does not occupy any hard disk space. More important files (directories) such as:  /proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/* Wait a minute. Oh, is it virtual memory [guest]?


This directory actually with/ Proc is very similar, but also a virtual file system, is also the record and core-related information.   includes currently loaded core modules and core detected hardware device information and so on.   This directory also does not account for hard disk capacity.

In addition to the contents of these directories, it is also important to note that because the root directory is related to boot, only the root directory will be mounted during the boot process, and the other partitions will continue to be mounted after the boot is completed. Because of this, the directory associated with the boot process in the root directory cannot be placed in a different partition than the root directory. 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 partitions. Please carry it down.

Two. 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 through the network (for example, the NFS server that talks to the server), then/ USR can really share it with other hosts in the local area network.

/usr is not the user's abbreviation, in fact, USR is the abbreviation of UNIX software resource, that is, the UNIX operating system software resources placed in the directory, rather than users of the 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\ of the Windows system, the combination of the two directories, 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:


File contents should be placed


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.


Most of the users can use the instructions to put them here. Please note the difference between him and/bin. (whether it is related to the boot process)


In the case of a file header (header) and a containing file (include) in a C + + program language, when we install some data in the Tarball Way (*.tar.gz), we use many of the included files inside.


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. Note that if you are using a x86_64 Linux system, there may be/usr/lib64/directory generated


The system administrator installs its own downloaded software (non-distribution default provider) natively, 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 original 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 directory


System directives that are required for non-system normal operation. The most common is the service instructions for some Web server Software (daemon)


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 files

/usr/share/doc: Software Miscellaneous File description

/usr/share/zoneinfo: Time zone files associated with the time zone


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.

Three. 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:


File contents should be placed


Some of the temporary archives that are generated during the operation of the application itself


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/var/lib/mysql/and the RPM database is put into/var/lib/rpm.


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


Very important. This is the directory where the login file is placed. There are more important documents such as/var/log/messages,/var/log/wtmp (log in information) and so on.


The directory where the personal e-mail address is placed, but this directory is also placed in the/var/spool/mail/directory, usually the two directories are linked files.


When some programs or services start up, their PID is placed in this directory


This directory usually places some queue data, so-called "queues" are data that is queued for use by other programs. 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.

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.

Four. Directory tree:

Under Linux, all files and directories start with the root directory. That is the source of all the directories and files, and then one branch down, so we also call this directory configuration: directory tree, the main features of this directory tree 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.

If we display the entire directory tree as a graph, and the more important file data is listed, then the directory tree schema is as follows:

Five. Absolute path and relative path

In addition to the FHS directory configuration that requires special attention, we also pay special attention to the file name section. 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 file name or directory name, such as/HOME/DMTSAI/.BASHRC, at which the root directory (/) begins to write;

Relative path:

The name of the file relative 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 represented by 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?

Cd/var/log (absolute)

Cd.. /var/log (relative)

Because you are under/home, so go back to the previous layer (. /) to continue moving towards/Var, paying 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 directives, which represent the working state of the previous layer and the directory in which it is currently located.

Example 1: How to enter the/var/spool/mail/directory first, then into the/var/spool/cron/directory?



Cd.. /cron


Because/var/spool/mail and/var/spool/cron are also in the/var/spool/directory. So there is no need to start writing from the root directory. This relative path is extremely helpful, especially for some software developers. In general, software developers will place the data in each relative directory within the/usr/local/. But what if the user wants to install to a different directory? You have to use a relative path.

Example 2: Network files often refer to similar./ data, what is the meaning of this directive?


Since the execution of the instruction requires the support of the variable, if your execution file is placed in this directory, and this directory is not the normal execution file directory (/bin,/usr/bin, etc.), at this time to execute the instruction must be strictly specified the execution file./represents the meaning of this directory, so. represents the execution of a file named in this directory.

Reference: "Bird's Linux Private cuisine"

Linux directory Structure

Related Article

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.