In-depth understanding of Linux soft links and hard links

Source: Internet
Author: User
I have never had a deep understanding of Linux soft links and hard links. a friend asked me this question last night, which suddenly aroused my interest. This morning, I looked at laruence's book and found it on stackoverflow. now I feel that my understanding is in place. at least... I have a deep understanding of Linux soft links and hard links.

I have never had a deep understanding of the link. a friend asked me this question last night, which suddenly aroused my interest. This morning, I looked at laruence's book and found it on stackoverflow. now I feel that my understanding is in place. at least this understanding is easy to remember. First, create an experiment. in our user directory, create a test folder, create a new file, and create soft and hard links for the file. As follows:

1vim file1 # Create a file 2ln-s file1 file1.soft # soft link 3ln file1 file1.hard # The following is a hard link. let's take a look at the details of these three files:

We found that the file attribute of the soft link is l, and the hard link is the same as the file, both are-, and the soft link file is relatively small, while the size of the hard link file is the same as that of the original file. Next, modify the file1 file, and then view the file information:


We found that, after modifying file1, file1.hard's modification time also changes, but file1.soft's file Time information does not change. Modify the file1.soft file and view the file information. We also found that the time information of file1 and file1.hard files has changed, while the time information of file1.soft files has not changed. Let's not talk about it. continue.
Linux kids shoes only know numbers, and others don't understand anything. so when we use Linux, we correspond to a number in many places, such as process numbers and permission values, files are also identified by numbers in Linux. this number is called the file index node (inode). each file has a unique index node. We can use "ls-I" to view the inode node information of the file, as shown below:



We are surprised to find that the inode node values of file1 and file1.hard are the same. at this time, I don't know if you suddenly realized that their inode values are the same, during file update, Linux finds the corresponding file based on inode and then updates the file. two files will be found for each update.
Finally, we will summarize the soft links and hard links in one sentence:
Soft link: it is equivalent to a shortcut. you can create soft links for all files.
Hard link: it is equivalent to an alias for the file. the linked file and the source file are actually the same file. Cannot be used as a directory.
 
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.