Some relationships between soft/hard links and Inode in a Linux system.

Source: Internet
Author: User

Objective:
It is well known that hard drives are an integral part of the computer, and no matter what system is running on the computer, the storage device is essential, and the Inode is a part of the disk storage that cannot be replaced. So I'd like to talk about some personal insights on inode and soft/hard links in Linux systems.

  目录:
    1. What is an inode

    2. What is a hard link

    3. What is a soft link

    4. Basic use of soft/hard links on Linux

    5. Link to soft/hard links and Inode

One, what is the Inode

    • To understand the inode, start with the file storage.
      The file is stored on the hard disk, and the minimum storage unit for the hard disk is called "Sector" (Sector). Each sector stores 512 bytes (equivalent to 0.5KB), and the file is not necessarily stored on contiguous sectors until the entire file is stored. So when a computer needs a file, it must
      You have to jump across different sectors to read all the contents of a complete file. It is conceivable how slow it is to read data, so people invent new ways to find a place to store the meta-information of the file, such as the creator of the file, the date the file was created, the size of the file,

What sectors the files are distributed to, and so on. This area of stored file meta information is called Inode, and the Chinese name is "Index node".

    • The inode typically takes up 1/10 of the size of the drive or smaller, and in our usual storage style each partition has its own inode, each corresponding to its own partition at least one storage unit as shown:
    • So when the inode is available, the computer extracts the information from the inode and then goes to the storage unit for each time. This reduces the number of long way, thus speeding up the read time.

Two, what is a hard link

  • A hard link, also called a link, is one or more filenames of a file. Again, the so-called link is simply the file name and the computer file system used by the node number linked together. So we can link to the same file with multiple file names, which can be in the same directory or different directories.
  • One of the most important features of the Linux file system is its file link. A link is a reference to a file so that you can see it in multiple places in the file system. However, in Linux, links can be treated as if they were the original files. Links can be executed, edited, and accessed in the same way as regular files. For other applications in the system, the link is the original file that it corresponds to. When you edit a file through a link, you are actually editing the original file. The link is not a copy.
  • Hard links can only reference files in the same file system. It refers to a file's physical index (also known as an inode) in the file system. When you move or delete the original file, the hard link is not broken because it refers to the physical data of the file and not the location of the file in the file structure. A hard-linked file does not require the user to have access to the original file, nor does it show the location of the original file, which can help secure the file. If you delete a file with a corresponding hard link, the file will remain until all references to it are deleted.
  • Hard links cannot cross file systems.
    Three, what is soft link
  • A soft link is also called a symbolic link, which contains the path name of another file. can be any file or directory that can link files from different file systems. There are basically no differences with shortcuts on Windows systems.
  • A soft link file is just a token of its source file, and when the source file is deleted, the linked file cannot exist independently, although the file name remains, but the contents of the soft link file cannot be viewed.
  • Soft links on Linux can cross the file system, just like you can create a soft link on the C: disk but the link to the target is a file on D:!
    Four, the basic use of soft/hard links on Linux

  • The test file is "Hello", and now we're going to create a soft link in the B3 folder, and when we're on the cat link, we'll see if "Hello" is displayed.
  • Now let's look at the nature of this soft link
  • So soft link we can think of it as a separate file, and the file is the path, if the source file is deleted then this soft link will have no meaning!
  • Let's look at the hard link, the hard link creation method is: ln to be linked to the file's absolute path link name also with just the file example, the command is: LN app/a/a2/a3/test Lianjie here is not illustrated.
  • Hard links show the effect, or that the usefulness of reaching the soft link is basically no different, the number of files that are hard-linked will be added 1 if you look at all the hard links we will find their size, inode, exactly the same! And if we delete the source file, this link will not be affected.
    Five, soft/hard links and inode connections
  • For soft links, this soft link has its own independent inode. And this soft link is also a file, from the storage level of the disk, we want to show that the file actually and soft links do not have any connection. Our link completes his mission when it finds a file of this path, and what is displayed or achieved is accomplished entirely by the document we find. Or that our soft link is a trigger effect!
  • For hard links It is completely different and hard links cannot span partitions. Files that are hard-linked are like a chance to revive when playing a game. As long as the inode count is not 0, no matter how to delete the file, the file is still strong!!!
  • In general, the inode of the soft link and the source file is not related, soft link is a complete individual! A hard link does not cause the source file to be copied again, but all links to the same file are the same hard-link inode, and the size is the same. Because each hard-link inode is the same, it causes each hard link to be real deal associated with this source file!

Postscript:
The first time you write a blog, you should continue. Write bad place everybody to forgive! In the future I will continue to share with you the understanding of Linux learning, only for sharing. Although you do not love to listen to, but I love to say Ah!!!

Some relationships between soft/hard links and Inode in a Linux system.

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.