Concept of Linux soft link and hard link

Source: Internet
Author: User
Concepts of Linux soft links and hard links 1. Linux link concepts Linux links are divided into two types: hard links and SymbolicLink ). By default, the ln command generates a hard link. [Hard connection] hard connection refers to the connection through the index node... concepts of Linux soft links and hard links 1. the Linux Link concept is divided into two types: Hard Link and Symbolic Link ). By default, the ln command generates a hard link. [Hard connection] hard connection refers to the connection through the index node. In a Linux file system, a file stored in a disk partition is assigned with an Index node number (Inode Index) no matter what type it is ). In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. A hard connection allows a file to have multiple valid path names. in this way, you can create a hard connection to an important file to prevent "accidental deletion. The reason is as described above, because there is more than one connection to the index node of the Directory. Deleting only one connection does not affect the connection between the index node and other nodes. only when the last connection is deleted will the connection of the data block and Directory of the file be released. That is to say, the true condition for deleting a file is that all hard connection files related to the file are deleted. [Soft connection] another kind of connection is called Symbolic Link. Soft-link files have shortcuts similar to Windows. It is actually a special file. In a symbolic connection, a file is actually a text file containing the location information of another file. 2. through experiments, we will learn more about [oracle @ Linux] $ touch f1 # Creating a test file f1 [oracle @ Linux] $ ln f1 f2 # Creating a hard connection file f2 for f1 [oracle @ Linux] $ ln-s f1 f3 # Create a symbolic connection file f3 [oracle @ Linux] $ ls-li #-I parameter to display the inode node information of the file total 09797648-rw- r -- 2 oracle oinstall 0 Apr 21 08:11 f19797648-rw-r -- 2 oracle oinstall 0 Apr 21 08:11 f29797649 lrwxrwxrwx 1 oracle oinstall 2 Apr 21 08:11 f3-> f1 from above as shown in the preceding results, the hard connection file f2 is the same as the inode node of the original file f1, both of which are 9797648. Inode nodes connected to files are different. [Oracle @ Linux] $ echo "I am f1 file"> f1 [oracle @ Linux] $ cat f1I am f1 file [oracle @ Linux] $ cat f2I am f1 file [oracle @ Linux] $ cat f3I am f1 file [oracle @ Linux] $ rm-f f1 [oracle @ Linux] $ cat f2I am f1 file [oracle @ Linux] $ cat f3cat: f3: No such file or directory: after the original file f1 is deleted, the hard connection f2 is not affected, but the symbolic connection f1 file is invalid. conclusion: you can perform some related tests and draw the following conclusions: 1 ). deleting a symbolic connection f3 does not affect f1 and f2; 2 ). deleting a hard connection f2 does not affect f1 or f3. 3 ). deleting the original file f1 does not affect the hard connection f2. Failed to connect to f3; 4). delete the original file f1 at the same time and hard connect f2. the entire file will be deleted.
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.