Linux hard links and soft links

Source: Internet
Author: User

There are two types of Linux links, one called hard links , and the other called Symbolic links (symbolic link). By default, theln command produces a hard link.

A hard connection is a connection made by an index node that allows a file to have multiple valid pathname so that the user can establish a hard connection to an important file to prevent " accidental deletion " the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, and the connection to the file's data block and directory will be released only if the last connection is deleted. That is, the condition that the file is actually deleted is that all the hard connection files associated with it are deleted.

2 Restrictions on hard connections:

not allowed to create hard links to directories

links can only be created between files in the same file system . This means that no hard links can be established between the two files on different hard disk partitions. This is because hard links point to the original file through nodes, and the I-node of the file may be different in different file systems.

A soft-link file has a shortcut similar to Windows . It's actually a special file. In a symbolic connection, a file is actually a text file that contains location information for another file.

[[email protected] ~]$ Touch f1        # Create a test file f1
[[email protected] ~]$ ln F1 f2          # create f1 " A hard connection file f2
[[email protected] ~]$ Ln-s F1 f3       # Create a symbolic connection file for f1 f3
[[email protected] ~]$ ls-li                #-I parameter display file inode node Information

grand total

622794-rw-rw-r--2 wzj wzj     0 01-12 21:59 F1
622794-rw-rw-r- -2 wzj wzj     0 01-12 21:59 F2
622796 lrwxrwxrwx 1 wzj wzj     2 01-12 22:00 F3, F1

as can be seen from the above results, the hard connection file f2 and the original file f1 inode nodes are the same, 622794 , but the inode of the symbolic connection file nodes are different.
[[email protected] ~]$ echo "I am fi file" >>f1
[[email protected] ~]$ cat F1
I am fi file
[[email protected] ~]$ cat F2
I am fi file
[[email protected] ~]$ cat F3
I am fi file
[[email protected] ~]$ RM F1
[[Email&nbs P;protected] ~]$ cat F2
I am fi file
[[email protected] ~]$ cat F3
cat:f3: No file or directory /span>

can be seen by the above test: when delete original file

3. Summary
1). Remove symbolic connection f3, has no effect on f1,f2 ; 2). Delete Hard connection f2 , no effect on f1,f3 ; 3). Delete original file f1 , no effect on hard connection f2 , resulting in symbolic connection f3 invalidation;
4). Delete the original file f1, hard connect f2 , the entire file will be really deleted

Linux hard links and soft links

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.