CentOS Learning Notes-Directory Configuration

Source: Internet
Author: User

Linux directory Configuration

The directory of Class Linux looks similar, why? The following excerpt from L Bird's Linux private dishes-Basic Study Directory sixth chapter, Linux file permissions and directory configuration 3. Linux directory Configuration

Linux directory configuration based on-FHS

Filesystem Hierarchy Standard (FHS), according to the official document of FHS (http://www.pathname.com/fhs/), Their main purpose 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 to follow FHS standards.

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 directories in the table above are some representative directories.

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

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

Most of the system's 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 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/: The 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 called Super Daemon Management.
  • /etc/x11/: 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 only the above, but there are many catalogs underneath our Linux you need to know. 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
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 /c/c++ and other programming languages such as the header and the containing file (include), when we install some data in tarball way (*.tar.gz way), we will use a lot of 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. 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 file (refer to this section), I believe it will give you a more in-depth understanding of the Linux operating system directory!

After reading the FHS standard, for hard disk segmentation, a bit of an idea?

According to the definition of FHS, it is better to 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. For example./home/dmtsai or. /.. /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 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!

CentOS Learning Notes-Directory Configuration

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