*inode*
When we need to open a file, often enter the command to open the file plus file name, the operating system will go to the hard disk to find the corresponding file, it should be known that the Unix/linux system does not use the file name to find the corresponding file, but through a called "File index node" Inode, which is used to store meta-information about the file, such as the creator of the file, the size of the file, and the time information of the file, and each file corresponds to an inode.
*inode content *
The inode of a file often contains the following information
FileName and file size
Number of File links
The owner of the file uid, the file belongs to the group GID
Read and Write permissions for files
Timestamp of file (Access: The time the file was last opened
Modify: The time of the last change in the contents of a file
Change:inode time of last change)
Location of file data block
You can use the Stat command to view inode information for a file
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/9D/wKioL1cFz4yAeUuTAAA2FB6GFc8982.png "title=" Inode.png "alt=" Wkiol1cfz4yaeuutaaa2fb6gfc8982.png "/>
You can also use the Ls-i file name to view the inode number of the file
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7E/A1/wKiom1cFzyWBMX9iAAAL3H7Qf54899.png "title=" Inode number. png "alt=" Wkiom1cfzywbmx9iaaal3h7qf54899.png "/>
On the surface we open a file by file name, in fact here the operating system will go through the following steps, first find the inode number corresponding to the file name, followed by the inode number to obtain the corresponding inode information, and finally according to the Inode information to find the location of the file data storage, read the corresponding file data.
* Hard Link *
Before I say the hard link to the file, I'd like to mention the deep copy problem in C + +, a shallow copy is a number of pointers pointing to the same piece of new space, there will be a problem in the delete, so we generally use a dark copy, deep copy is also useful reference counting, The reference count is a counter that counts how many pointers point to the same piece of space, and when the counter is zeroed, the space is freed, or multiple pointers share a space and the space is not freed.
File hard link is actually the idea of reference counting, Unix/linux system allows multiple files corresponding to the same inode number, that is, you can use different file names to access the same file, can also be modified, but will affect all hard-link files, delete a file, does not affect the access of other files, This is hard link.
You can use the LN source file destination file to create a hard link, and when created, the file's inode information is +1, such as:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7E/A2/wKiom1cF4MDhBAqHAABMWHPUWWE011.png "title=" Hard link. png "alt=" Wkiom1cf4mdhbaqhaabmwhpuwwe011.png "/>
When you delete a hard-link file, the number of links to the file in the Inode information is 1, and when the number of links to the file is reduced to 0 o'clock, the inode number is reclaimed and the block area is used for the next newly created file:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/A2/wKiom1cF4PyCmT7bAABYBW7QM9Q332.png "title=" Hard link delete. png "alt=" Wkiom1cf4pycmt7baabybw7qm9q332.png "/>
* Soft Link *
For a chestnut, there is file A and file B, the inode number is not the same, but the content in file A is the path of file B, so access to file A is actually access to file B, at this time file A is called File B's soft link (soft link) or symbolic link (symbolic link).
You can use the Ln-s source file target file command to create a soft link to a file, and the number of links in the file inode information in a soft link does not change:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7E/9E/wKioL1cF406QzvMBAABT894Riqc666.png "title=" Soft links. png "alt=" Wkiol1cf406qzvmbaabt894riqc666.png "/>
A soft link file a depends on file B, and when file B is deleted, the system will error when opening file a:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7E/A2/wKiom1cF5pXQSDzYAABohyJ-D48390.png "title=" Soft link delete. png "alt=" Wkiom1cf5pxqsdzyaabohyj-d48390.png "/>
Finish
This article is from the "Knock Code good Sleep zzz" blog, please be sure to keep this source http://2627lounuo.blog.51cto.com/10696599/1761261
Inode and hard links and soft links