Soft and hard links in Linux

Source: Internet
Author: User

Hard links on soft and hard links in Linux

Hard link, if file B is a hard link to file A, the inode number of a is the same as the inode number of B, that is, an inode node corresponds to two different file names, two file names point to the same file, and A and B are completely equal to the file system. If one is deleted, it has no effect on the other one. Each additional file name increases the number of links on the Inode node by one, each deleting a corresponding file name, and the number of links on the Inode node is reduced by one until the 0,inode node and the corresponding data block are recycled. Note: Files and filenames are different things, rm a deletes only a this file name, and a corresponding data block (file) only when the Inode node link number is reduced to 0 will be collected by the system.

Soft links

Soft links (soft link), also known as Symbolic links (symbolic link), if C is a soft link (A and c are filenames), the inode number of A and b of the Inode node number is not the same, A and B points to two different inode, Therefore, it points to two different pieces of data. However, the data block of C is only the path name of a (which can be used to find the directory entry for B). A and C are "master-slave" relationships, and if A is deleted, C still exists (because two are different files), but pointing to an invalid link.

Observation

The right blue memory block stores the file metadata, the left memory stores the file data, a is a file, the B file is a hard link, and C is a soft link. A and B have the same inode number, point to the same memory address, C points to another memory address, but C points to the memory where the address of the a file is stored, so you can find a file.

Difference
Hard Links Soft links
Principle The same inode is stored with the original file The address index inode where the original file is stored in the pointed memory
Inode number Same as the original file Inode Different from the original file Inode
Delete original file Does not affect hard links Soft links cannot be viewed
Whether you can point to the directory No OK
Whether you can cross-partition No OK
Command ln filename Hdname ln-s filename Stname

Soft and hard links in 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.