The zero-based Linux 20th chapter (INODE and block detailed one)

Source: Internet
Author: User
Tags parent directory

The zero-based Linux 20th chapter

Hello~~ is a week come to provoke ~ ~, small series even if busy, also want to take time to give lectures to students ~ and ... No wages yet ...

You can no longer find how to work hard and love your small make-up ~ ~ is not AH ~ passers-by a ~ ~

(↑ shy passers-by)

Passers-by B: "Small series!!" You tease passers-by again!! ”

How? is not the small part of the week is not updated, passers-by do not want to small?? (Poor expression)

(Blush of Pride) Passerby B: "I ...." It's not possible.

2333 Good ~ ~ ~ Joking, then, in order to save the students time and small part of the time, small series will no longer nonsense ~ Start this chapter of the theme ~ ~

The previous chapter, the small series to the students detailed introduction of the MV Mobile Files command, uh .... Some students said that is not a small part of the explanation, the small part of the very wronged said ~ ~ Small series have a sentence do not know to say ... No... Small make a statement must say, in fact, the MV command for us, its two options are enough, and the small part in the previous chapter mentioned some professional terminology, in ... Well.. In the 18th chapter, the CP Copy File command is explained in detail. ~ ~ Each command students do not have to deeply study the use of its various options, Linux commands spicy, how can all remember to live it ~ ~ So, in the case of some do not know how the command is used, Small series at a very early time to tell the students how to check the use of commands help ~ students only need to check the help, you can quickly know how to use ~ ~

Small series at the end of the last chapter, have told the students this chapter to give the students to introduce what is the inode and block, do not know the students in the following there is no review it ~ ~ ~ no matter ~ Anyway there are small in the AH ~ but, Can not rely too much on the small part of the lecture, students still rely on their own understanding of ~ ~

What are the inode and block of the file?

Block:


Block is the data block that stores the data, and in the computer's physical device, the disk becomes the hard disk, which is used to store the data. And these data have two kinds of metadata and data, meta-data is the attributes of the file, the small series before the students told, here is not much to say, and block storage is the real data.

When we write to the file, the system assigns US block blocks to store the data, and the size of a block is usually specified when the file system is formatted, typically 1kb,2kb,4kb; Format File System Small series has not been mentioned, the students first have this concept, after the small to talk about the disk Management time will be talked about ~ ~ So the return to the theme ~ Obviously, a block for some data volume, a block is unable to save, at this time the system will be assigned to the file block, Until the data can be saved.

Then, the block in the system is not infinite, (the small part said "block in the system" may not be accurate, but also not too much problem ~) block of how much, depending on the size of the physical disk (hard disk), the larger the disk, the more blocks can be allocated, because the larger the disk, Partitions can be divided into more space, the format of the file system when the more blocks, they are proportional to; however, although the number of blocks is determined by the size of the disk, but this is the total number, small in the first chapter to the students to introduce the installation of virtual machines, in this period simply explained to the disk partition, then, Why do you want to partition the disk?

partitions do not store data separately, physically, the data in these different partitions is stored in the same place, which is stored on the physical hard disk. We partition a hard disk and give the partition a filesystem, just separate them in the logical layer (note that the logical layer), so that if one of the partitions is out of the question, does not affect the other partitions, logically separates them, but in fact, the existence of data on the hard disk is still out of order (not stored in sequence).

Since it is in the logical layer division, then the block should also be divided, so the size of the storage in each partition is actually divided by the number of blocks, the storage capacity of the partition is large, the block naturally more points.

Small part of the above also said, although the logical layer of the disk partition, each partition has a file system, the data exist under different partitions, but in fact, the data on the disk, is still disorderly storage, since it is disorderly storage, then how do we find the corresponding data?

Inode:

In order to find these unordered data on the disk, we need a "pointer" that takes us to find this data. Just like there are so many rooms in the hotel, how to express a room exactly? They will use a floor number + room number to accurately represent a single room, such as: Number No. 0405 represents the fifth room on the four floor. Well.. The small part thought has been described clearly, so, here the "pointer" is also the same meaning, and this takes us to find the data of the "pointer", we call it: the file inode number . However, just because the inode called the file may not be accurate, because he also includes additional information about its files.

Since it is the inode of the file, it indicates that each file, including the directory, has a corresponding inode. The data is stored in the block, so what about the meta data? Yes, the inode number contains the file's metadata: permissions (mode), the owner and group information of the file, the size of the file, the timestamp, the pointer. When we create a file or directory under a partition, it assigns an inode number to the file, and the inode contains all the metadata for the file, so why is there no file name? In fact, the name of the file is just for the user to see, in fact, each file in the file system is the inode number to identify the file, the Inode number is responsible for pointing to its data block (block), so the inode number under the same partition should be a unique value, In the small series has not yet to the students to tell the hard link, the students can understand so. 

Why is it that it is unique under the same partition? Students can imagine, small series also use hotel room number for example, one of the hotel has 0201 this room number, can't other hotel can have 0201 this room number? The answer must be no. The different hotels are equivalent to different partitions. Students can imagine, two hotels have 0201 this room, but the room inside the facilities and decoration of the style will not be the same right ~ here is still the same, different partitions will have the same inode number, but its point of data is not the same, therefore, the inode number can not cross the partition, Because there are also the same inode in other partitions

Students can imagine, its hotel room is limited, so the room number of each room is also limited, the larger the size of the hotel, the more rooms built, the room number will be more. This is also the case, under a partition, the inode number of the file is limited, the larger the partition size, the more inode number. This also means that the number of files under the partition is also limited, even if there is a lot of storage space, if there is no inode number, can no longer create files?

Then, small make up to take everyone to experiment ~ ~ (Note Oh, small series will use some not to speak of the order, first to the students briefly mention ~)

In Linux, we can use the DF command to see the mount and space usage of the partition first, and note that the partition that starts with/dev/is the disk:

Where blocks is the total space size , the unit is K,used is the space size that has been used ,use% has used a percentage of the total size of the space .

We can use df-i to see the partition inode number usage:

Inodes is the number of inode numbers under this partition , iused is the number ofinode numbers already in use ,ifree is the number of free inode numbers,iuse% is the percentage of the total number of inode numbers that have been used .

Well, our tests are still being tested in the/app/directory, and the small part just said that each file created will be assigned an inode number.

And the small borrowing strategy to build an empty file, with the ls-l command to view the details of the file, the small part of the highlighted section represents the size of the ordinary file, you can see that the empty file size is 0, that is, no matter how many small borrowing strategy built empty files, its size will not be/app/partition space to fill, The small series creates 24,413,689 files in this directory:

Well... This operation is not a small part of the students, the next chapter on the ~ ~ Because of too many files, so the creation time will be very slow, here the small series deliberately create more than one file

.... Five minutes later ...

Wow ~ too slow, no experiment no experiment ~ ~

Now the inode to 100,000, still need a lot of, well ~ ~ Small make up not to demonstrate ~ ~ Students only need to know, when the partition under the Inode, no matter how much space remaining, will no longer be able to create files.

Passers-by a: "Small series of adults ~ I have a question to ask ~"

Wait, small make know you want to ask what, you want to ask, the file name is to the user to see, Linux is to use Inode to distinguish the file, you want to ask why the file name is the same when the conflict will occur, right?

Passer-by: "Yes, yes."

Well... Passers-by is a good question to ask ~

Linux does use inode numbers to identify a file, and when we create a file and name it, we assign the file an inode number, and the block is allocated when the data is written.

The small series before to the students to tell the LS command when said, with Ls-i to see the inode number of a file

As you can see, the inode number of the file is 67, and the directory is created in this directory, and the inode number is viewed

The inode number for this directory is 68, so the small series uses ls-l to see the size of their two files.

You can see that the size of the normal file is 0, and the directory does not have any files, but its size is 6, small series now from the other directory to find a file with data and copy it to the/app/zxc/directory

It can be seen that the size of the original passwd file is 2321 bytes, but after copying to the/app/zxc/directory, the original 6-byte directory, now only 20 bytes, but passwd the size of the file itself is copied to the directory has not changed, this is why?

In fact, when we use ls-l to view the details of a directory, the size of the directory displayed is only the size of the directory itself, not the total size of the directory and all the files under that directory, which is not the same as the windows we normally use.

So, the size of the original directory itself is 6 bytes, why copied into a 2321-byte file, the size of the directory itself has become 20 bytes? And what exactly is this extra 14 bytes of storage?

In Linux, the directory is not stored in the file data, the small part of the above, the data in the disk is stored out of order, the Inode pointer in the file to help us point to the location of its data block (block), and the directory is not a single file, It is the name of the file under the directory and the inode number corresponding to the file name , so there is an inode record of the filename corresponding to the file's parent directory, so we have created two files of the same name in the same directory why the conflict, this problem will be solved ~ ~

So what do we do on the ground floor when we copy files, move files, and delete files? What else can a pointer in the inode point to, in addition to a database (Block)?

Small make up to students so a problem, with a curious psychology to look forward to the next chapter of the small series ~ ~ ~

Alas?? Unconsciously have been so late to provoke ~ ~ Students early to rest OH ~ ~

The zero-based Linux 20th chapter (INODE and block detailed one)

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.