Linux File System Preliminary

Source: Internet
Author: User

in a Linux system, if we want to know the details of a file, the easiest way is the LS command. For example, as you can see: When you enter the command "ls-l old" in the shell, some of the old files are displayed below

Information. The detailed meanings represented by each part of the output are analyzed from left to right. The first part of the output consists of 10 characters. The first of these characters is used to represent the type of file. So let's start by saying that the file types in the Unix/linux system are good.


File type: the

In fact, in the Linux system is mainly two kinds of files, one is a regular file (regular files), there is a folder (directory).

It may be very strange to start with. How can a folder be a file? In fact, a folder is just a special file that stores the name of the file or subfolder under the folder and the corresponding I-node (including basically the structure of all information about the corresponding file).

Of course, in addition to the two file types mentioned above, there are also: block devices files (blocks special device). Character device file (character special device), FIFO (pipeline). Socket (socket), Symbolic link (symbolic link) These kinds of file types.

The details are not to be unfolded here.

As in the first place is '-'. Indicates that the file is a regular file. Other types of files that appear through this bit should also be very easy to infer.

File permissions:

Let's take a look at the meaning of the post 9-character representation.

Say 9-bit, in fact we divide them into 3 groups, each group of representatives means almost the same. We all know that the Linux system is a multi-user system, so for a file, there may be someone other than the creator who wants to manipulate the file.

At this point, it is necessary to set the operation permissions of the file.

The three sets of characters from left to right are the creator (user) of the file, and the same group member of the creator of the file. Other than the above two users (others). The 3 characters of each group, from left to right, are displayed as RWX, where R represents the Read permission, W represents the Write permission, and X represents the permission to run. For example, as seen, I would like to read a file named new. But all of its privileges are blocked. When I enter the command: More new, the shell will prompt for insufficient permissions.

Other operations can also be obtained by analogy.

But there is a god-like user in Linux, the legendary root or Superuser (Superuser).

It has all the permissions on the system. The ability to manipulate arbitrary files. So the limitations mentioned earlier have no effect on it.


Number of Links:

The number 1 to the right shows the. The file has 1 links. There are two types of links, hard links and symbolic links (symbolic link). The number of hard links shown here should be.

The hard link is the corresponding inode that runs the file directly. The symbolic link does not, it simply includes the location information of the linked file. Similar to shortcuts in Windows.

It is important to note that very often, what you call deleting a file is simply deleting a link to the file.

To really delete the contents of a file, you must satisfy two conditions: 1. The number of links to the file is 0. 2. There is no process to open the file.

UID and GID:

As already mentioned, a file must have been created by a user. Then naturally in the file information needs to be saved, the creator of the file, that is, user-id abbreviation UID, at the same time there is the creator of the group's Id,group-id, referred to as GID. So the next monster monster is the group where the file creator Monster and monster are respectively corresponding.

File Size:

Then the size of the corresponding file is displayed, and the file size in the sample shows 0, in bytes.

It is important to note that if the type of the file is linked, then its size is the number of characters of the file name of the file it is running.

File time:

The next show is the file time. For a file, generally saved 3 times: 1.st_mtime, the last time the file was changed (modification times), 2.st_atime, the last time the file was opened (access times) 3.st_ctime, The last time the file state changed (changed status).

The most puzzling of all is the St_mtime and St_ctime, the document has been changed. Does that state change? State changes. That must be a file change, huh? That's not the truth. The first st_mtime refers to the file content changes, and st_ctime state refers to the file corresponding to the inode stored in the information changes, such as various permissions Ah, UID. GID and so on. So it's totally different.

File name:

Show in the final nature is the file name, for the file name is to say, it is not saved in the file corresponding inode, but in the corresponding folder file. This has led to a very interesting phenomenon. Is that we want to delete a file, we do not need the file regardless of the permissions, but the file is the folder where the Write permission and run permissions. Because we delete a file is the number of links that will reduce the corresponding inode for that file. and remove the file name from the appropriate folder file.



PS: The above is the basic knowledge of Linux file system by the command ls-l filename extension. Of course there are a lot of details that are not involved. File systems are far less simple. If there are any mistakes, please point them out in time and let me correct them.

Students who want to discuss can also comment on the message. (*^__^*) hehe ...

Number of references: Advanced programming for the UNIX environment

Linux File System Preliminary

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.