Linux hard-Link files

Source: Internet
Author: User

Hard link file

= = allows only hard links to files, and cannot be hard-linked across partitions, because different partitions may have the same inode number. Hard links to directories are not allowed. ==

1. Hard links and Inode related

To view the inode number of a file using Ls-i

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091455_520.png "style=" border-style:none; "/>

2. Create a hard link
> Create a hard link to/tmp/1.txt
[[email protected] ~]# ln /tmp/1.txt /tmp/1_hard.txt[[email protected] ~]#  ln -s /tmp/1.txt  /tmp/1_soft.txt[[email protected] ~]# ls -lt  /tmp/Total dosage  8lrwxrwxrwx. 1 root   root    10 6 Month    9 14:59 1_soft.txt -> /tmp/1.txt-rw-r--r--.  1 root    root     0 6 month    9 14:53 4.txt-rw-r--r--.  1 root   root     0 6 Month    9 14:53  3.txt-rw-r--r--.  2 root   root   390 6 Month    9  14:52 1_hard.txt-rw-r--r--.  2 root   root   390 6 Month    9 14:52 1.txt

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091500_985.png "style=" border-style:none; "/>

> View inode numbers for 1.txt and 1_hard.txt
[[email protected] ~]# ls -it /tmp/16975321 1_soft.txt  33634053  34516975320 4.txt         822288 23416975319  3.txt       33634051 11116914255 1_hard.txt   50768750 22216914255 1.txt       16777285 allinlinux16890432  2.txt         822276  systemd-private-0f4b60569c224727b1ec0153a8598630-vmtoolsd.service-qcx2tt16777289 user1.txt       14404 allin2  822290 666          17024017 tmp 

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091502_8.png "style=" border-style:none; "/>

2.1 Interpretation

1.txt and 1_hard.txt are each other's hard links, there is no source file and the target file said.

inode is a string of characters that is used to mark a file (directory) and to record all information about the file (directory). Including the contents of the file is also stored in the inode number.

1_hard.txt and 1.txt two files all point to the same inode, stating that all the information for both files is consistent. So two identical files, whether Two copies of storage space? The answer is no. Two files point to the same inode, that is, to the same content, not the same as the copy file, occupying two copies of storage space.

so you can understand hard links: a new shell (1_hard.txt), like the original Shell (1.txt), refers to something that corresponds to the same inode. There is actually only one thing, two enclosures, so storage space occupies only one copy.

Removing any one of the files (the shell) does not affect the content information stored in the inode number, because there is also a file (shell) pointing to the inode, but an inode, at least one shell (file point), can exist.


This article is from the "Linux Road" blog, make sure to keep this source http://allin28.blog.51cto.com/12931477/1933862

Linux hard-Link files

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.