The difference between a soft link and a hard link under Linux

Source: Internet
Author: User

Linux The difference between a soft link and a hard link

linux The above is divided into two parts: metadata and data. User data, which is the file data block ( data block linux is part of the file's metadata, but it does not contain the file name, inode The index node number) is the unique identifier of the file, not the filename. The file name is only for the convenience of people's memory and use, the system or program through the inode number to find the correct file data fast. The process of getting the contents of a file from a filename for a program:

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20161020/1476960104485244.png "title= "1476960104485244.png" alt= "Blob.png" style= "height:auto;vertical-align:middle;border:0px;"/>

in  linux   view   in the system Inode  # you can use the command  stat  or  ls–i

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20161020/1476960116880633.png "title= "1476960116880633.png" alt= "Blob.png" style= "height:auto;vertical-align:middle;border:0px;"/>

Hard Links:

A hard connection is a connection that is made through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). In Linux, multiple file names point to the same index node that exists. In general, this connection is the hard link is directly based on the node table (inode), the establishment of a hard link to a file, the node table will update the count value above. For example, a file is connected two times (hard link), the value of this file is 3, and regardless of the 3 file name of any one of the access, the effect is exactly the same, but if you delete any of them, only the value of the calculation minus 1, does not delete the actual content, (Any existing file itself is a hard connection) only when the count value becomes 0 and no hard links point to the actual deletion of the content.

Hard Link Features:

The file has the same inode and data block;

Only files that already exist can be created;

Cannot cross file system for hard link creation;

The directory cannot be created, only the file can be created;

Deleting a hard-link file does not affect other files that have the same inode number.

Soft Links :

The Symbolic connection (symbolic link), also called the link soft link, has a shortcut similar to Windows. It's actually a special file. In a symbolic connection, a file is actually a text file that contains location information for another file. A soft link does not use the Inode number directly as a file pointer, but instead uses the file path name as a pointer (soft link: file name + data part –> The pathname of the destination file). The software has its own inode and has a small space on the disk to store the path name. Therefore, the soft link can cross file system, also can and directory link! Second, a soft link can link to a nonexistent file name, but it will not open its link until it has been created.

Features of soft Links:

Soft links have their own file attributes and permissions, etc.;

You can create a soft link to a nonexistent file or directory;

Soft link can cross file system;

Soft links can be created on files or directories;

When you create a soft link, the link count inlink not increase;

Hard links and soft links are an important concept in the Linux file system, which involves index nodes (index node, also called Inode) in the file system, and the index node object is one of the four basic concepts of the Linux virtual file system (VFS). By dissecting the links and differences between hard links and soft links, we have a better understanding of the common file model of VFS in Linux. And let Linux normal users and system administrators correctly use hard links and soft links to help file system developers get the knowledge of inode.


The difference between a soft link and a hard link under Linux

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.