What is the comparison between hard link and symbolic link?

Source: Internet
Author: User

Today I will talk about the differences between hard links (physical links) and symbolic links (similar to Windows shortcuts?

First, we should know:

Each archive occupies one inode. The archive content is directed by the inode record;

To read this file, you must point to the correct inode number through the directory record file name to read data through the block.

Hard link: adds a file name in the directory to the association record of an inode number without occupying space.

Note: hardlink only writes one more associated data to the block in a directory, without adding or reducing inode blocks.

For example, if my system has a/root/crontab object link of/etc/crontab, that is, these two files are linked to the same inode, naturally, all the information about the two object names except the object names will be the same ). Actual Situation

It can be as follows:

[[Email protected] ~] # Ln/etc/crontab/root/crontab

[[Email protected] ~] # Ll-I/etc/crontab/root/crontab

1912701-rw-r -- r -- 2 root Root 255 Jan 6 2007/etc/crontab

1912701-rw-r -- r -- 2 root Root 255 Jan 6 2007/root/crontab

Disadvantages: you cannot view the private kitchen food on page 261.


Symbolic Link: An Independent file is created, which allows the data to read and link the data of the file.

Key Point: after the source file is deleted, the symboliclink file will "fail" and will always say "cannot start a file ."

Case !』. The original file name cannot be found!

For example, create a symbolic link file to link to/etc/crontab:

[[Email protected] ~] # Ln-S/etc/crontab crontab2

[[Email protected] ~] # Ll-I/etc/crontab/root/crontab2

1912701-rw-r -- r -- 2 root Root 255 Jan 6 2007/etc/crontab

654687 lrwxrwxrwx 1 Root 12 Oct 22/root/crontab2->

/Etc/crontab

From the above results, we can know that two files point to different inode numbers, of course, two independent files exist! And connect

An important part of file close is that it will write the "file name" of the target file. You can see why the size of the link file is 12.

What about bytes? Because the file name "/etc/crontab" on the right of the arrow (-->) has a total of 12 English letters, each of which occupies 1 BYes,

The file size is 12 bytes!

Disadvantage: if you do this link: ln-S/bin/root/bin

If you enter the/root/bin directory! This directory is actually the/bin directory, because you have made a link

File !』 So if you go to the/root/bin directory and kill the data in it, um!

The data in/bin is lost! Please pay attention to this! So use "RM/root/bin" to delete this link file.

Right! Because it is similar to a windows shortcut, remember.


This article from the "no trace of Sorrow" blog, please be sure to keep this source http://2845621599.blog.51cto.com/8221220/1437382

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.