CentOS (vii)--linux file type and directory configuration

Source: Internet
Author: User

This essay will supplement the file types of Linux systems and the directory structure of Linux (Linux directory Management and permissions are very important, especially in Linux installation database class software).

One, Linux change file permissions in two ways

In a previous essay, a way to change file permissions under a Linux system has been explained in detail. There are nine basic properties of the Linux file, namely the Read/write/execute attribute of the Owner/group/others group , which is a group of 3 bits in the 9 attributes, which can be used to represent the individual properties by using a number:

R:4w:2x:1 three properties (r/w/x) for the same group (owner/group/others) are cumulative, such as when the property is [-rwxrwx---]:
Owner = rwx = 4+2+1 = 7 Group = rwx = 4+2+1 = 7 others=---= 0+0+0 = 0

So we can use this number if we want to change the permissions of a file, for example:

[email protected] home]# Touch Test.txt[[email protected] home]# ls-l-rw-r--r--.  1 root    root            0 April  19:47 test.txt


At this point we can enter the following command to modify

[Email protected] home]# chmod 766 test.txt
[Email protected] home]# ls-l
-rwxrw-rw-. 1 root root 0 April 19:47 test.txt
Then we found that the file permissions became what we just needed. owner=rwx, group=rw-, other=rw-

The above-mentioned way to modify the permissions of the file is relatively simple, but if you do not know R, W, x the corresponding number of three permissions to represent the meaning of the estimate is a bit difficult to understand, so here is another way to change the file permissions--by the symbol type to change the file permissions

In the above introduction, we know that there are 9 properties of the file, basically 9 attributes are (1) User (2) group (3) Others these 3 groups! Then we can represent the properties of these 3 groups through U, G, O! Also, a represents all 3 groups! Then the read and write properties can be written as R, W, X!

chmod

U

G

O

A

+ (Join)

-(remove)

= (set)

R

W

X

File or directory

If we were to change the property of a file to "-rwxr-xr-x", it would basically be:

    • User (U): With readable, writable, executable permissions; u=rwx
    • Group and others (G/O): Have read and Execute permissions. Go=rx
[Email protected] home]# chmod u=rwx,go=rx test.txt[[email protected] home]# ls-l-rwxr-xr-x.  1 root    root            0 April  19:47 test.txt

We see the ability to change the permissions of a file in this way as well. Note : In the middle of the u=rwx,go=rx of the first line of command there is no space.

If we don't know the properties of the original file in advance, but want to increase the permissions that everyone in the Test.txt file can write, we can do this:

[Email protected] home]# chmod a+w test.txt[[email protected] home]# ls-l-rwxrwxrwx.  1 root    root            0 April  19:47 test.txt

Also, if we want to remove all user executable permissions for the file, we can use this method:

[Email protected] home]# chmod a-x test.txt[[email protected] home]# ls-l-rw-rw-rw-.  1 root    root            0 April  19:47 test.txt

The above describes two ways to change file permissions, I prefer the first way to modify, you can choose according to their preferences in the appropriate way to modify the file permissions

Ii. Linux file types and extensions

In a Linux system, any hardware device or other device is in the form of a file, and even the interface of data communication is responsible for the special files, so there are many types of Linux files, out of our common-or D to represent the general file and directory files, What kinds of documents are there?

1. Types of documents

When we use the ls-l command, we can observe the first column of the 10 characters, the first character is the type of the file. What kinds of file types are there in addition to the common general file (-) and catalog file (d)?

  • ordinary files (regular file): is the type of file that we are accessing, in terms of the attributes shown by Ls-al, the first character is [-], for example [-rwxrwxrwx]. In addition, according to the contents of the document, but also can be divided into:
    • Plain text file (ASCII): This is the most common type of file in a Linux system, known as a plain text file because the content is data that we humans can read directly, such as numbers, letters, and so on. Almost as long as we can use it as a set of files belongs to this file type. For example, you can release "Cat ~/.BASHRC" to see the contents of the file. (Cat is an instruction to read the contents of a file)
    • Binary (binary): Our system actually knows only and can execute binary files (binary file) in Linux executable files (scripts, text-type batch file not counted) is this format for example, we often use the cat The command is a binary file.
    • Data format files: Some programs read certain files in a particular format during operation, and those files in a particular format can be referred to as data files. For example, when the user logs on, our Linux logs the logged-in data in the/var/log/wtmp file, which is a data file that can be read through the last command! However, when using cat, it will read garbled characters because it belongs to a special format file.
  • directory: The first property of a directory is [d], for example [drwxrwxrwx].
  • Connection file: just like a shortcut under Windows System! The first property is [l] (lowercase in English l), for example [lrwxrwxrwx];
  • device and device files: Some files related to the perimeter and storage of the system are usually concentrated in the/dev directory! It is usually divided into two types:
    • Block device file: is some storage data to provide system random access to the interface device, for example, hard disk and floppy disk is! You can read and write randomly in different chunks of the hard drive, which is a group device! You can check the/DEV/SDA yourself, and you'll find the first property is [b]!
    • Character (character) device files: This is the interface device for some serial ports, such as keyboards, mice, and so on! The features of these devices are "one-time read" and cannot truncate the output. For example, you can't let the mouse "jump" to another screen, but instead "swipe" to another place! The first property is [C].
  • Data Interface file (Sockets): since it is called a data interface file, it is assumed that this type of file is usually used for data on the network. We can start a program to listen to the client's requirements, and the client can communicate the data through the socket. The first property is [s], which is most commonly seen in the/var/run directory.
  • data transfer file (FIFO, pipe): FIFO is also a special type of file, and his main purpose is to solve the error caused by multiple programs accessing a file simultaneously. FIFO is the abbreviation for first-in-first-out. The first property is [P].

In addition to the device files are very important in our system files, it is best not to arbitrarily modify outside (usually only the root user can modify!) ), another interesting file is the link file. If you often catch the app on the desktop, you should know that there are so-called " shortcuts" underneath Windows. Similarly, you can simply consider a link file under Linux as a shortcut to a document or directory. As for the socket and FIFO file is difficult to understand, because these two things compared with the program (process), this wait until later study! In addition, you can check the instructions on the system through the man FIFO and the mans socket!

2.Linux file extension:

Basically, the Linux file is not called "extension", a Linux file can be executed, and his first column of the 10 attributes, and the file name is not at all related. This concept is not the same as the Windows situation! Under Windows, the file name extensions that can be executed are usually. exe. bat and so on, and under Linux, as long as you have x in your permission, for example [-rwx-r-xr-x] That means the file can be executed!

However, can be executed and can be executed is not the same as the success of ~ For example, in the root directory of the Install.log is a plain text file, if through the modification of the permission to become-rwxrwxrwx, this file can really execute success? Of course not ~ because his content simply does not have the data that can be executed. So, this x represents the ability of the file to execute, but if it succeeds, it will have to look at the contents of the file.

Nevertheless, we still want to be able to understand what the file is by extension, so we will usually indicate what kind of file it is with the appropriate extension. There are several common extensions at the bottom:

    • *.sh: script or batch file (scripts), because the batch file is written using the shell, so the extension is compiled. Sh;
    • *z, *.tar, *.tar.gz, *.zip, *.tgz: Packaged compressed files. This is because the compression software is gunzip, tar and so on, due to different compression software, and take its associated extension!
    • *.html, *.php: Web-related files, respectively, representing HTML syntax and PHP syntax of the Web page file!. html files can be opened directly using a Web browser, as for. php files, you can browse through the server side of the client browser to get the operation Page results!

Basically, the name of the file on the Linux system really just lets you know what the file might be used for, and the actual execution will still require permission specification! For example, although there is a file for the executable file, such as the common/bin/ls this shows the file attributes of the instructions, however, if the permissions of the file is modified to be unable to execute, then the LS becomes unable to execute!

3.Linux file length and filename restrictions

Under Linux, when using a preset ext2/ext3 file system, the file name length is limited to:

    • The maximum allowable file name of a single file or directory is 255 characters;
    • The full file name containing the full path name and directory (/) is 4,096 characters.

Because of the Linux in the text interface some of the instructions to operate the relationship, in general, you set the name of Linux under the file, it is best to avoid some special characters better! For example under these:

* > < &! [ ] | \ ' "' () {}

Because these symbols in the text interface, there is a special meaning! Additionally, the file name begins with the decimal point "." , this file is "hidden file"! At the same time, because of the command release, often use the-option and other options, so it is best to avoid the file name at the beginning of-or + to name!

Third, the Linux directory structure

In a previous essay on the preliminary analysis of the Linux directory structure, in the Linux system, all files and directories are the root directory "/" start. It is the source of all directories and files, and then a branch down, a bit like a tree. We usually call this directory configuration as: "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.

Because there are so many developers of Linux, if everyone develops their own directory configuration method, it can cause a lot of management problems. So, there is a standard called Filesystem Hierarchy Standards (FHS) came out.

This FHS ( http://www.pathname.com/fhs/ ) is actually just a specification of what kind of files should be placed in the main directory under the root directory (/). FHS defines the two-layer specification, the first layer is/under the various directories should be placed on what content of the file data, such as/etc should be placed configuration files,/bin and/sbin should be placed executable files and so on. The second tier is defined for the sub-directories of the/USR and/var directories. For example,/var/log places system registry files,/usr/share places shared data, and so on.
In fact, FHS is based on 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)
unchanging (Stati c) /usr (software placement) /etc (config file)
/opt (third party collaboration Software) /boot (boot with core)
variable (variable) /var/mail (user mail) /var/run (program-related)
/var/spool/news (newsgroup) /var/lock (Program-related)
    • 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 addition, 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 spelled. the absolute path is: The file name or directory name that is written by the root (/), such as/HOME/XIAOLUO/.BASHRC, and the relative path is the file name that corresponds to the current path. such as./home/xiaoluo or http://www.cnblogs.com/home/xiaoluo/, 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, currently in the/home directory, if you want to enter the/var/log directory, you can use the following two ways to write:

    • Cd/var/log (absolute)
    • 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.

We can take a look at the directory configuration structure under the "/" root directory by ls-l/this command:

[[email protected] home]# ls-l/Total dosage 102dr-xr-xr-x.   2 root root 4096 March bindr-xr-xr-x.  5 root root 1024 March 21:34 bootdrwxr-xr-x.  Root root 4096 March 11:20 cgroupdrwxr-xr-x. Root root 3800 April 12:58 devdrwxr-xr-x.   157 root root 12288 April 12:59 etcdrwxr-xr-x.  8 root root 4096 April 20:16 homedr-xr-xr-x.  Root root 4096 March 21:28 libdr-xr-xr-x.   Root root 12288 April 5 20:52 lib64drwx------.   2 root root 16384 March 10:27 lost+founddrwxr-xr-x.   3 root root 4096 April 12:59 mediadrwxr-xr-x.   2 root root 0 April 12:54 miscdrwxr-xr-x.   3 root root 4096 March 21:40 mntdrwxr-xr-x.   2 root root 0 April 12:54 netdrwxr-xr-x. 3 root root 4096 March 15:28 optdr-xr-xr-x.  191 root root 0 April 12:52 procdr-xr-x---.   Root root 4096 April 20:40 rootdr-xr-xr-x.   2 root root 12288 April 5 12:26 sbindrwxr-xr-x.   7 root root 0 April 12:52 selinuxdrwxr-xr-x.  2 root root 4096 September srvdrwxr-xr-x. Root Root 0 April 12:52 sysdrwxrwxrwt.  Root root 4096 April 13:50 tmpdrwxr-xr-x.  Root root 4096 March 10:37 usrdrwxr-xr-x. Root root 4096 April 5 20:57 var

Are we already familiar with the attributes of the previous ones?

If you want to look at a more complete tree directory, the entire Linux system tree can be used to represent:

We can see that all of these directories are attached to the "/" root directory, which is what we commonly called "tree-like directory." According to the FHS definition, the file contents that should be placed within each directory should be as follows:

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!
/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 one of the files under this directory to access a device that is more important than /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 types of code: ~: Represents the current user's home directory, and ~xiaoluo: it represents xiaoluo 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)!
/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. (Our disc image files are usually mounted in the media directory)
/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 the data at/TMP should be removed when booting
/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! 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 account for hard disk capacity
Usr The second level of content by the FHS specification, in/usr This directory, contains the system's main program, graphics interface required files, additional library, the local side of the software installed by itself, as well as shared directories and files, etc., can be found in this directory. In fact, he is a bit like the "Program Files" and "WinNT" in the Windows operating system to combine the two directories! The important sub-directories under this directory are:
  • /usr/bin,/usr/sbin: directory where the general identity user and the system administrator can perform file placement;
  • /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: The library files directory of each application software;
  • /usr/local: The default directory where the native-side software installs itself. It is also available for the/OPT directory. After you have installed Linux, basically all the equipment you have, but the software can always be upgraded, for example, you want to upgrade your proxy service, the software is usually the default installation is in the/usr/local (Local is "locally" meaning), at the same time, After the installation of the resulting execution files, in order to be different from the original execution of the system, so the upgraded execution file is usually placed in the/usr/local/bin this place.
  • /usr/share: A directory for shared file placement, such as the bottom two directories:
  • /usr/share/doc: Place some system documentation, for example, if you have grub installed, then look it up under that directory and you can find the GRUB documentation! It is very convenient!
  • /usr/share/man:manpage file directory, when using man, will go to query the path! For example, when you use the man ls command, you will find the contents of/usr/share/man/man1/ls.1.gz this document!
  • /usr/src:linux system-related program code placement directory, such as/usr/src/linux as the core of the original code!
  • /USR/X11R6: Almost all of the execution files required for the X Window system within the systems are placed here!
 /var   This directory is also important and is the second-level directory content of the FHS specification. His main place is for the system execution process, the normal changes in the file placement directory. For example, a cached file (cache), or a log file that is changed at any time, is placed in this directory. In addition, some of the database files that are written during the execution of the software, such as the MySQL database, are also written in this directory! The following important directories are:
  • /var/cache: Some temporary disks in the process of the program files;
  • /var/lib: The program itself executes the process, need to use the data files placed in the directory, for example, locate this database and MySQL and RPM database system, are written in this directory.
  • /var/log: directory where the login file is placed. It's important! For example/var/log/messages is a file of all login files!
  • /var/lock: Some appliances have a one-time write feature, such as tab (Tape drive), at which point, in order to worry about being disturbed by others to disrupt the operation of the action, therefore, The device will be lock (locked) to make sure that the device can only be used by a single program!
  • /var/run: When some programs or services are started, their PID will be placed in this directory!
  • /var/spool: is where some queue data is stored. For example, when the host receives the e-mail, it will be placed in the/var/spool/mail, if the letter is temporarily not sent out, it will be placed in the/var/spool/mqueue directory, the user task Assignment (cron) is placed in the/var/spool/cron Of

Several categories of particular importance

    • /etc: This directory is where the system configuration files are placed, including the account number and password (/etc/passwd,/etc/shadow) on your system, as well as the set values (/etc/sysconfig/*) to be used when booting, as well as the configuration files of each major network service. are in this directory. This means that if the files under this directory are deleted or are dead, we will have to spend a lot of time restoring the files in this directory. Therefore, it is generally recommended that this directory be backed up!
    • /usr/local: Although the importance of this directory has now been moved to/OPT, I am still more accustomed to placing myself in this/usr/local directory with software that I have developed myself or installed on my own. If your Linux system is a multi-person condominium, it is necessary to develop a good operating habit. Then the habit of installing software should be well built up AH ~ do not install it at random! Put it in the/usr/local or under the/opt!
    • /var: This directory is an important intermediate staging data during the operation of the management system, such as/var/lib and/var/run. In addition, the final data such as Mail/var/spool/mail is also placed in this directory in addition, almost all the services of the login file (can record who, when, where to log in the machine, what to do and so on information! are placed in the/var/log directory, so this directory is also important.

Thanks to the author of this essay!

CentOS (vii)--linux file type and 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.