Linux inode, soft links, and hard links

Source: Internet
Author: User

I have read a lot of information about inode and soft links in recent days. I was surprised to find that there was a conflict between the information. Some even have conflicts with themselves. Now I feel that I have initially understood these three concepts and published them here, hoping to reduce such errors on the network.ArticleMisleading new users. Ln-s myfile.txt mylink // create a symbolic link, that is, a soft link ln myfile.txt hardlink // create a hard linkInodeThe Linux File System (hard disk) is divided into two parts: inode table and data area. There are many inode on the inode table. Each inode records the attributes of an archive and the datablock on which the archive is distributed (that is, the pointer we call ). Inode has two functions: record file attributes and pointers. Data area consists of multiple datablocks, which record the actual content of the file.Hard Link

Hard link only adds the connected data of the file in a directory! 1. for example, my/home/vbird/crontab is a hard link file, which is linked to the/etc/crontab file, that is, in fact,/home/vbird/crontab and/etc/crontab are the same file, but there are two directories (/etc and/home/vbird) that record the related data of the crontab file! That is to say, I know that the inode of crontab is placed at a BY THE connected data recorded by the block of/etc, and the joined data under the directory of/home/vbird, contab also refers to inode at! Therefore, the inode and block of the crontab file have not changed, and some have only two directories that record the associated data. 2. when you use hard link to set the link file, the disk space and inode count will not change! From the above description, we can know that hard link only writes one more connected data to the block in a directory, so inode and disk space will not be used. 3. When we modify the content of a file, the content of the file that is hard-linked to each other will also change. If we delete a file that is hard-linked to each other, other files will not be affected. 4. since hard link establishes data connections on the same partition, there are limits on hard link:. cannot span filesystem. b. cannot link the directory. 5.false the hardware link of me.txt has been established: ln me.txt hard_me.txt ....... Run ls-L:-RW-r -- 3 Younes 40 2009-12-03 hard_me.txt, where the numbers in the orange background represent the number of hard links pointing to the file.
Soft link
1. A Soft link is also called a symbolic link. It is different from a hard link. A Soft link file is only a mark of its source file. After the source file is deleted, the linked file cannot exist independently. Although the file name is retained, we cannot view the content of the soft link file. 2. the symbolic link and Windows shortcuts can be assigned an equal sign. The files created by the symbolic link are an independent new file, which occupies inode and block calls.
Differences between hard and soft links
(1) soft connections can span file systems, but hard Connections cannot. The practice is to use a shared file to connect the aa.txt text file in Windows to BB, CC. ln-s aa.txt/root/BB in the/root directory in Linux. Ln aa.txt/root/BB failed. (2) I node issues. No matter how many hard connections direct to the same I node, the number of connections at the node increases. As long as the number of connections at the node is not 0, the file will always exist, whether you delete the source file or the connected file. Only one file exists (in fact, there is no source file to connect to, because they point to the same I node ). When you modify the source file or any connected file, other files will be synchronized. Soft links do not directly use the I node number as the file pointer, but use the file path name as the pointer. Therefore, deleting the connection file does not affect the source file. However, deleting the source file does not affect the file to be directed. The soft link has its own inode, and there is a small space on the disk to store the path name. (3) A soft connection can be used to connect a non-existent file name. (4) soft connections can be used to connect directories. Note: I node: it is a data structure used within UNIX to describe file features. We usually call I a file index node (information node ). The I node contains most important information about the file, including the address of the file data block on the disk. Each I node has its own logo number, which is called the document sequence number. Information contained in the I node: 1. file type 2. File owner relationship 3. file access permission 4. File time cut. Hard connection refers to the connection through the index node. In a Linux File System, a file stored in a disk partition is assigned with an index node number (inode index) No matter what type it is ). In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. A hard connection allows a file to have multiple valid path names. In this way, you can create a hard connection to an important file to prevent "accidental deletion. The reason is as described above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the connection between the index node and other nodes. Only when the last connection is deleted will the connection of the data block and directory of the file be released. That is to say, the object will be deleted. Soft-link files are similar to Windows shortcuts. It is actually a type of special file. In a symbolic connection, a file is actually a text file containing the location information of another file. Soft link is another file, which can be understood as a pointer. Operations on this file, except deletion, are directly directed to the file. Because it is a real file, it occupies disk space. Hard links can be regarded as not a file. They are just an alias of an actual file. They are used to prevent misoperation of a real file. After a hard link is established for a file, they are aliases of each other, deleting any of these aliases will only delete the alias, and the actual file will not be deleted. Because only the alias does not have any other information, it does not occupy the disk space of the original file size.
Reference: http://blog.chinaunix.net/u1/36085/showart_412257.html http://dianping.blog.51cto.com/427241/95041 http://hi.baidu.com/lamron/blog/item/bf5a6a4c9af311fbd62afcc6.html

 

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.