The difference between soft links and hard links in a Linux file system

Source: Internet
Author: User

1. Hard link is to create an inode pointing to the block, there is the ability to prevent accidental deletion. Because deleting a file actually deletes the inode information and cuts the connection between the Inode and the block. When a hard link is made to a file, deleting the file will only reduce the number of links to the file, and the file will be completely deleted when the number of links is 0 o'clock. Soft links like Windows system shortcut, is a complete file, has its own inode and block,block content is the file name of the original file. When the original file is deleted, the soft link becomes invalid and there is no function to prevent accidental deletion.


2. The file size is different. Because the hard link is the block that points to the original file, the file size of the hard link is consistent with the original file size. And the soft link is a new file, block is the original file name, so the size of the soft link file is generally 4K, that is, the size of a block.


3. Hard links cannot be made to directories and cannot be done across partitions. Soft links are all available.


To create a hard-link command:


ln file FileNew #file为原文件名, FileNew is the new file name.



To create a soft link command:


Ln-s file FileNew #file为原文件名, FileNew is the new filename.


Detailed code

Create hard links, hard links for ABC ABC2

[[email protected] backup]# ll total dosage 20-rwxr-xr-x 1 root root 19688 February 23:54 abc[[email protected] backup]# mkdir tests[[ Email protected] backup]# LN ABC tests/abc2[[email protected] backup]# ll total dosage 24-rwxr-xr-x 2 root root 19688 February 23:54 A Bcdrwxr-xr-x 2 root root 4096 February 23:55 tests[[email protected] backup]# CD Tests[[email protected] tests]# ll total dosage 20-r Wxr-xr-x 2 root root 19688 February 23:54 abc2[[email protected] tests]# ls-i794342 abc2[[email protected] tests]# CD. /[[email protected] backup]# ls-i794342 ABC 794343 tests[[email protected] backup]#


Differences between soft links and hard links in the Linux file system

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.