What is the difference between a soft link and a hard link in a Linux system?

Source: Internet
Author: User

Linuxsystemfiles in the file are file names and data in theLinuxthe above is divided into two parts: metadata and data. User data, which is the file data block (Data Block), the data block is where the real content of the file is recorded, and the metadata is the additional attributes of the file, such as size, creation time, owner, and so on. In theLinux, in metadata, in theInodeNumber (Inodeis part of the file's metadata, but it does not contain a file name,Inodethe index node number) is the unique identifier of the file, not the filename. File name is only for the convenience of people's memory and use, the system or program throughInodefind the correct file data quickly. The process of getting the contents of a file for a program by its file name


View inode numbers in a Linux system using command stat or ls–i



Hard Links:

A hard connection is built directly on the node table (inode), and the count value above the node table is updated when a hard connection is established to a file. For example, a file is connected two times (hard connection), 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, Just minus 1of the value, not delete the actual content, (any existing file itself is a hard connection) only the count value becomes 0 that is no hard link to the time will be real delete 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 :

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 inodeand 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 i_nlink not increase;

hard links and soft links areLinuxan important concept in a file system that involves an index node in a file system(Index nodealso known asinode), and the Index node object isLinuxVirtual File System(VFS)one of the four basic concepts. By dissecting the links and differences between hard links and soft links, we can better understandLinuxinVFSthis generic file model. and letLinuxregular users and system administrators use hard links and soft links correctly to help file system developers getInoderelated knowledge.

Article Source: Ops Tribe

What is the difference between a soft link and a hard link in a Linux system?

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.