Linux Shipping Koriyuki Hard links and soft links

Source: Internet
Author: User

It's better to know the file before you know it.

We know that files have filenames and data, but this is divided into two sections on Linux: User data and metadata (metadata).

User data, which is the file data block (data block), is the place where the real content of the file is recorded;

Metadata is an additional property of the file, such as file size, creation time, owner information, and so on.

In Linux, the inode number in the metadata (the Inode is part of the file metadata but does not contain a file name, the inode number is the index node number) is the unique identifier of the file and not the filename. File name is for the convenience of people's memory and use

The system or program looks for the correct file data block through the inode number, so the file read process reads the inode first and then finds the block data.

and Linux introduced two kinds of links: hard links and soft links, for the system to solve the shared use of files, while providing hidden file path, save storage, while increasing the security of the file.

You may have seen this for a long time or a face, do not hurry to read the example, you understand.

One, hard links

    is one or more filenames of a file- -so the simple answer is not a crazy??

Popular talk hard link is a copy of your person, you when you do what he does, but you are not in, he will not disappear, will not be bound by you.

But I have another one to tell.---------ln command---> ln [options] ... [File] ...

You look at the article only need to master two

              ln target file creates a personalized name----> Hard Links

             Ln-s target file Create a personalized name------> Soft Links       

LN is the-----that creates the link > then it's gone.

    

LN has learned to now formally lecture hard links

Let's get to know him through the features of hard links.

1, the file has the same inode and data block,

     

Let's start by creating a file, and now I'm going to add a hard link to it,

     

It's created.

     

Did you create it?? and use Ls-li to see the inode.

This is the same as the inode. See here there must be a vague understanding of it, look at a picture:

    

2, hard links are not space-intensive

You know, just remember, don't take up disk space.

3, only files that already exist can be created

When you create a source file to be in, you can not out of thin out a link file it??

4, the directory cannot be created, only the file can be created

For directory creation is a soft connection, hard links only create file links oh

5, no matter which file you enter, the other one will.

That's how powerful the Replicators are.

6. Delete one file another is unaffected

Let's delete the source file to see:

          

Not affected, still can write can read

Note: It is not possible to create a directory!

        

      

And you can't cross the file system.

That's how I understand a root system, a dev.

Two, soft connection

To complete a hard link:

Soft links like your projection, why do you say that? You have him, you're not there, he turns wood.

Look at the read flow of the soft link

Create a soft link first:

    

Did you see the mistake?

When creating, the content to be created cannot be taken with/so the directory name cannot coincide with the file name.

Soft links can do hard links, that is, you can file, or directory OH

Features: 1, soft links have their own file attributes and permissions, Inode different

Do not know if you have found the above picture, has been described in detail

File attributes are different.

2, you can create a soft link to a nonexistent file or directory

Is this much more powerful? But you created, the source file is no longer, the creation is useless

          

How are we going to make him useful??

The answer is to create the source file

    

Look, it's all alive,

Also can be launched, if the source file is deleted, the link file is not available, invalid

      

     

3, file content sharing, regardless of where there are new files or content, the other side will have

    

4, a soft connection can be created on a file or directory

That's understandable.

5, when you create a soft link, the link count I_nlink does not increase

    

No matter how much you create it will not increase, but the hard link will have oh let's see:

    

6, deleting the soft link does not affect the file being pointed to, but if the original file being pointed to is deleted, then the related soft connection is called dead link (that is, dangling link, if the path file is re-created, the dead link can revert to the normal soft link)

Well, it's over, the next blog is gone!

Linux Shipping Koriyuki Hard links and soft links

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.