Inode
In Linux, all files are stored in file form.
For a file, it has two properties, one is its own property, also known as the metadata of the file, indicating the properties of the file itself, such as who the creator of the file, which group is, what the permissions of the file, the time of creation, the time of the modification ... The stat command can be used to query the properties of the file itself, the specific usage stat File;file is the file you want to query;
Another property is written to the contents of the file, also known as its data properties, which can be viewed or modified by commands such as Cat,vim. The main role of the file is to store data, but if the file's own attributes of the information, then the file view, modification, movement and other operations will become extremely complex, the same will aggravate the consumption of system resources, so the file metadata is also extremely important.
Linux contains a large number of files, in order to facilitate the query of files and other operations, create a file node number inode is very necessary. Inode node number is equivalent to the file "House", when the file read and write operations, it is necessary to obtain the file "house number", and then can be based on the "number" directly find the location of the file, these complex addressing operations occur within the system, do not need to participate in the human.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/23/wKioL1ea3ROCzr_KAAAlnQdyYxg297.gif "title=" 4.GIF " alt= "Wkiol1ea3roczr_kaaalnqdyyxg297.gif"/>
As shown, you can view the metadata information for the file by using the Stat command.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/24/wKiom1ea5GXjtGIVAAArhzEoUmo241.gif "title=" 20.GIF "alt=" Wkiom1ea5gxjtgivaaarhzeoumo241.gif "/>
From that, we can have a clearer understanding of the Inode table structure, which stores information about the properties of the file itself, as well as pointers to the data blocks, and by looking at the file system, you can see how much information an index node can store in terms of the size of each chunk of data. If the direct block pointer is able to "arrange" all the data in the file into the specified data block, then there is no need to use the indirect block pointer, if the file is too large, the direct block pointer is used up, but the data is not stored in the data block, then the indirect block pointer is enabled, it points to not the specific data block, Instead, a pointer to the next file block is pointed to the data block by a pointer to a block, so that the storage capacity of the index node is greater than its actual storage capacity, and the triple pointer is the same principle.
A directory is the mapping of filenames and file Inode numbers under the directory.
The General Inode table consumes 1% of the file system disk space.
CP and Inode
Allocate a free inode number, generate a new entry in the Inode table, create a directory entry in the directory, associate the name with the inode number, and copy the data to generate a new file.
RM and Inode
The number of links is decremented so that the inode number released can be reused
The data block seems to be in the free list
Delete a catalog entry
The data is not actually deleted immediately, but when another data is used, it will be overwritten with the MV and Inode
Create a new directory entry with a new file name
Delete old directory entries corresponding to the file name
does not affect inode tables (except timestamps) or location on disk, no data is moved
If the target and source are not on a file system, then CP is equivalent to MV+RM
2. Soft and Hard links
2.1 Hard Links
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/25/wKiom1ea8B7y7PG_AAApeVl_-C0017.gif "title=" 23.GIF "alt=" Wkiom1ea8b7y7pg_aaapevl_-c0017.gif "/>
Creating a hard link adds additional record entries to reference the file
Corresponds to a physical file on the same file system
Each directory references the same inode number
Increase number of links at creation time
When deleting files:
Link for RM command decrement count
File to exist, at least one link, when the number of links is 0 o'clock, the file is deleted, there is no pointer to the data block that the file is located, cannot be read.
Cannot span drives or partitions
ln filename [linkname]
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/24/wKioL1ea8ADi6JF3AAANVeXxxo8375.gif "title=" 22.GIF "alt=" Wkiol1ea8adi6jf3aaanvexxxo8375.gif "/>
2.2 Soft Links
A symbolic link points to another file
Ls-l display the name of the link and the referenced file
The content of a soft link is the name of the file it references
The directory can be
Can span partitions
A path to another file whose size is a string length pointing to a path, without increasing or decreasing the target file Inode reference count
ln-s filename [linkname]
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/24/wKioL1ea8DeQjdjIAAAxgRXvZ2k868.gif "title=" 21.GIF "alt=" Wkiol1ea8deqjdjiaaaxgrxvz2k868.gif "/>
Understanding of inode and soft-hard links