Hard connection and symbolic link (soft connection) under Linux __linux

Source: Internet
Author: User

There are two types of links, one called hard links (Hard link) and the other is called Symbolic links (symbolic link, also known as soft links). By default, the LN command produces a hard link.

(a) Hard link

1. The syntax to produce hard links

# ln Source file target file (Note: You cannot create a hard link for the directory)

2. About Inode

An inode is an index node that is translated into Chinese. Partition of each storage device or storage device (storage device is hard disk, floppy disk, u disk ...) After being formatted as a file system, there should be two parts, one for the inode and the other for the Block,block to store the data. The inode is the information that is used to store the data, including the file size, the owner, the attribution user group, the read and write permissions, and so on. The Inode indexes information for each file, so there is a value for the inode. The operating system according to the instruction, can through the Inode value the quickest to find the corresponding file.

A hard connection is a connection made through an index node. In a Linux file system, a file stored in a disk partition is assigned a number, called an index node number (Inode index), regardless of its type. In Linux, multiple file names point to the same index node. Generally this connection is a hard connection. The effect of a hard connection is to allow a file to have multiple valid pathname, so that users can build hard connections to important files to prevent "accidentally delete" functionality. The reason for this 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 index node itself and other connections, and only when the last connection is deleted will the file's data block and directory connections be freed. That is to say, the file is actually deleted.

3.inode the same file is a hard link file

In the Linux file system, the file with the same inode value is a hard link file, that is, different file names, the inode may be the same, an inode value can correspond to multiple files.

Inode values the same file, their relationship is hard linked to each other. When we modify the contents of one of the files, the contents of each file that is hard linked are also changed. If we delete a file that is a hard link relationship, the other files are not affected.

(ii) Soft links (Symbolic links)

In contrast to hard connections, there is another connection in the Lnux system called a symbolic connection (SYMBILC link), also known as a soft connection. Soft link files are somewhat similar to Windows shortcuts. It is actually a kind of special file. In a symbolic connection, a file is actually a text file that contains the location information for another file.

1. Syntax for generating soft links

# ln-s source file or directory destination file or directory

2. About Soft Links

Soft links are also called Symbolic links, which differ from hard links, and soft link files are just a token of their source files. When we delete the source file, the linked file cannot exist independently, although the file name is still preserved, but we cannot view the contents of the soft link file.

It is worth noting that when we modify the contents of the linked file, it means that we are modifying the contents of the source file. Of course the properties of the source file will also change, and the properties of the linked file will not change. When we delete the source file, the link file only has a filename, because the source file is lost, so the soft link file does not exist. This point is different from the hard link;

(iii) sample

Touch F1 (Create a F1 file)

LN F1 F2 A hard connection of a F2

Ln-s F1 F3 creates a F3 soft connection

At this point, if the deletion of F3, F1,f2 has no effect, if the deletion of F2, F1,F3 also have no effect, if you delete F1, because F2 also applies f1, so does not affect the F2 node, the touch created the file still exists, but at this point F3 because it is a soft connection, resulting in F3 If you delete f1,f2, then the file with the best touch will be deleted

Related Article

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.