Deep understanding of the directory structure of Linux systems (very detailed summary)

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 important, we begin to understand the Linux directory structure of knowledge   when using Linux, If you go through ls–l/you will find that there are a lot of 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 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, the FHS is based on the past experience has been continuously revised, FHS based on the use of the file system and whether the user is allowed to change, andThe record is defined as a form of four interactions, which is somewhat like the bottom of the table: shareable (shareable) non-shareable (unshareable)/usr (static)////(software placement)/etc (configuration file)/opt (third party software)/ Boot (boot and CORE) variable (variable)/var/mail (user email)/var/run (program-related)/var/spool/news (newsgroup)/var/lock (program-related)four-medium type:1. Shareable: can be shared to other systems mount the use of the directory, so including the execution of files and users of the message, is able to share to other hosts on the network mounted directory; 2. 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. 3. Constant: Some data will not change frequently, follow the distribution without change. For example, a function library, file description file, the system administrator manages the host service configuration file and so on; 4. 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): 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. According to the above reasons, FHS that the root directory (/) should contain the following subdirectories: directory should be placed in the contents of the file/bin system has a lot of files placed in the directory, but/bin 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 will be used to boot 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 present in this directory in the form of files. Simply by accessing a file in this directory, you are accessing a device. More important than the files have/dev/null,/dev/zero,/dev/tty,/dev/lp*,/dev/hd*,/dev/sd* and so on/etc system major configuration files 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 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. Other, the following important directories are:/etc/init.d/: All pre-set startup script for all services are 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. /home This is the system preset user 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 current user's home directory, and ~guest: Represents the home directory of users named guest. The/lib system has a much more functional library, and/lib places the function libraries that will be used at boot time, as well as the function libraries 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). /mediamedia is the media of English, 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's homeThe directory is placed in the same partition as the root. /sbinlinux has a lot of instructions to set up the system environment, these instructions only root can use 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. /srvsrv can be regarded as the abbreviation of service, which is the data directory that some services need to use after the network service is 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/. 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 we need to understand, as follows: directory should be placed in the file content/lost+found This directory is used in standard EXT2/EXT3 file system format will be generated by a directory, The goal is to place some missing fragments in this directory when the file system is in error. This directory usually exists at the top level of the partition slot, for example if you add a hard disk to/disk, which will automatically generate a directory like this/disk/lost+found/proc the 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 very similar to/proc, is also a virtual file system, mainly records and core-related information. Includes core modules that are currently loadedAnd the core detected by the 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:/etc: Profile/bin: Important execution File/dev: Required device file/lib: function library required to execute the file and core required module/sbin: Important system execution files these five directories must not be separated from the root directory in different partitions. Please carry it down. two./usr meaning and content: 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: The directory should place the contents of the file/usr/x11r6/for the X Window system important data placed in the directory, the reason is named X11R6 because the last X version of the 11th version, and the 6th time release of the meaning. /usr/bin/The vast majority of users can use the instructions are placed here. Please note the difference between him and/bin. (whether it is related to the boot process)/usr/include/c/c++ and other programming languages such as the header (header) and the include file (include) placement, when we install the software in tarball manner (*.tar.gz Way), the installation of certain data, will use many of the included files inside. The/usr/lib/contains the function libraries for each application, the object file, and the execution file or script that is not commonly used by the general 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 generation/usr/local/administrator to install their own downloaded software (not distribution default provider), recommended to install to this directory, This will be 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 do it by yourself/Usr/local to see, the directory is also has bin, etc, include, Lib ... The secondary directory/usr/sbin/The system instructions that are required for non-system normal operation. The most common is that some Web server Software service Instructions (daemon)/usr/share/Place the shared files, the data placed in this directory is almost no hardware architecture can read the data, because almost all of the text file. These are also common in this directory:/usr/share/man: Online Help file/usr/share/doc: Software Miscellaneous file Description/usr/share/zoneinfo: Time zone file 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./var meaning and content: 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 secondary directories are: directories should be placed in the file content/var/cache/the application itself will produce some of the temporary archive/var/lib/program itself executed during the process, need to use the data files placed 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 placed in/var/lib/rpm to/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 conditions, so the device must be locked (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 will be locked, and the second person will have to be unlocked (that is, the previous person ran out) to continue to use/var/log/is 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/Some programs or services start, their PID will be placed in this directory/var/spool/this directory usually put some queue data, so-called "queue" is queued to wait for other programs to use 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. Since FHS is only the file or directory data that defines the contents of the top (/) and sub-tiers (/usr,/var) should be placed, in itsAt his sub-directory level, it can be configured with the developer on their own. 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 feature of this directory tree is: The directory tree starting point is the root directory (/, root), each directory can not only use the local side of the Partition file system, you can 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 pathIn 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 file names/paths are written according to the following: absolute path: The name of a file or directory that starts with the root directory (/), such as/HOME/DMTSAI/.BASHRC; relative path: The name of the file that corresponds to the current path. such as./home/dmtsai or http://www.cnblogs.com/home/dmtsai/, and so on. Anyway, the beginning is not a relative path 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? Copy the code code as follows: 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 special attention to these two special directories:. : Represents the current directory, or can be used./to represent;. : 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: Copy the Code code as follows: CD/VAR/SPOOL/MAILCD. /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? Note: Since the execution of the instruction requires variable support, 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 this directory, named RThe un.sh file.

Deep understanding of the directory structure of Linux systems (very detailed summary)

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.