directory Structure of Linux systems

Source: Internet
Author: User

Preface

For every Linux Learner, Understanding The directory structure of a Linux file system is a crucial step in learning Linux . , in-depth understanding Linux The file directory structure of the standard and detailed features of each directory, for our good Linux The system is important, let's start to understand Linux knowledge about the directory structure

a . directory tree (directory tree):

Under Linux, the file system looks like a tree under Linux, so we can refer to the structure of the file system as a tree structure, and all the files and directories start with the root directory. That is the source of all directories and files, and then a branch down, so we also call this directory configuration is: directory tree, the directory tree starting point is the root directory (/, root); the top of the Linux filesystem is/, we call/ Is the root of Linux, the file system 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.

Shown in the figure:

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 http://www.pathname.com/fhs/is 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.

a . root directory  (/)  the meaning and content of:

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:

Directory

File contents should be placed

/bin

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.

/boot

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.

/dev

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.

/etc

The main configuration files are placed in this directory, such as the user'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.   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 directories are:/ETC/INIT.D/ : Preset startup script for all services 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 configuration file directory for the various services that are called Super daemon management.

/ETC/X11/ : various profiles related to X window are here, especially xorg.conf or Xf86config two x  The configuration file for the server.

/home

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.

/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-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

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.

/mnt

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.

/opt

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.

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

/sbin

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

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.

/tmp

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:

Directory

File contents should be placed

/lost+found

This directory is a directory created using the standard EXT2/EXT3 file system format, which is intended to place missing fragments in this directory when an error occurs in the file system. This directory usually exists at the top level of the splitter slot, for example if you add a hard drive to/disk, which will automatically generate a directory under this system/disk/lost+found

/proc

This directory itself is a virtual file system (Vsan filesystem) Oh. The information he placed is in memory, such as system core, travel 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/* and so on. Oh, is it virtual memory [guest]?

/sys

This directory is in fact very similar to/proc, is also a virtual file system, mainly records and core-related information. Includes the core modules currently loaded and the 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:

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 to put them here. Please note the difference between him and/bin. (whether it is related to the boot process)

/usr/include/

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.

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

/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 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

/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 files

/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.

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:

Directory

File contents should be placed

/var/cache/

Some of the temporary archives that are generated 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/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

/var/log/

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.

/var/mail/

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.

/var/run/

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

/var/spool/

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 . absolute path vs. 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 http://www.cnblogs.com/home/dmtsai/, 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?

Command:

Cd/var/spool/mail

Cd.. /cron

Description

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./run.sh data, what is the meaning of this directive?

Description

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. Run.sh represents the execution of a file named run.sh in this directory.

Catalogue Description

The following are the basic directory structures and functions under Linux :

/
root directory.
/boot
Directories such as boot programs, kernels, and so on.
/sbin
The host directory of commands that the superuser can use.
/bin
The directory in which commands can be used by ordinary users. Commands in Linux are generally stored in the /bin directory;


/lib
The shared library directory of the program under the root directory.
/dev
Device Files directory.
/home
Home directory for normal users ($HOME directory
/root
$HOME directory for user root
/etc
The global configuration file holds the directory.
/usr
This directory contains the command library files and files that are not modified in the usual operation.
/proc
Special Files directory.
/opt
Optional file directory.
/mnt
Temporary mount directory.
/media
Mount the media device directory.
/var
A directory in which content changes frequently.
/tmp
Temp file directory.
/lost+found
The location where the files are recovered.

directory Structure of Linux systems

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: info-contact@alibabacloud.com 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.