Hard links and soft links under Linux

Source: Internet
Author: User

This article summarizes from:

Https://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/index.html#fig2

A file can be represented by:

where the filename is the name we can see.

The inode is included in the metadata (metadata), which records additional attributes of the file, such as file size, creation time, and so on.

The inode is the index node number and is the unique identifier of the file. You can use the command:

Ls-i

To view

Data blocks is a file block that records the actual contents of a file.

Here's one thing to say:

When we use rm to delete files, we simply dismiss the filename and inode references, and generally do not destroy the file data.
A hard link, however, is equivalent to adding an alias to the same inode.

So when you delete a file with RM, you can also access it through another filename if you create a hard link to the inode.

How to create a hard link:

ln Oldfile NewFile

A soft link is to create a data block that stores another filename in the data block.

So when we delete file with RM, then cat Softlink will not get the output of the actual file.

How to create a soft link:

Ln-s Oldfile NewFile

Use the ls-l command to see the number of links to the file, which appears in the second column of the output.

When you create a soft link, the number of links to the file is not added

Also, you can see the symbol, which points to the source file from the soft link file .

Using the LS-I directive, you can find that the inode number of the hard-link file is the same as the source file, and the inode number of the soft link file is different from the source file, which is the same as the above analysis.

Hard links and soft links 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.