Differences between symbolic links and hard links in Linux

Source: Internet
Author: User

There are two different types of links: Soft link and hard link. Modify one of them. The hard connection points to the node (inode), and the soft connection points to the path (PATH)

Soft link file

Soft links are also called symbolic links. This file contains the path name of another file. It can be any file or directory that can be linked to files of different file systems. It is similar to the shortcut in win. A linked file can even link a non-existing file, which leads to a problem (or "Symptom") that is commonly called "broken chain". linked files can even link themselves cyclically. Similar to recursion in programming languages.

Command Format:

Code:

Ln [-S] source_path target_path

 

Hard link file

The info ln Command tells you that the hard link is another name of an existing file, and the hard connection command is

Code:

Ln-D existfile newfile

Reference:

There are two restrictions on hard-link files

1. Hard links cannot be created for directories;

2. A link can be created only between files in the same file system.

When you perform read/write or delete operations on hard-link files, the results are the same as those of soft-link files. However, if we delete the source file of the hard link file, the hard link file still exists and retains the expected content. At this time, the system "forgot" that it was a hard link file. And regard it as a common file. Modify one of them, and the connected file is modified at the same time.

Interpretation 2

The difference between a hard link and a symbolic link is that the hard link has the same I-node as the original file, that is, they are the same indexes pointing to a storage space. the symbolic link can be understood as the index pointing to the index of the original file. it is different from the original file. so if there are three files, A is the original file, B is the hard link of A, and C is the symbolic link of. no matter the file or directory content changes, it will change the content of other files. for the deletion of the original file, C will become unavailable, but it has no impact on B. deleting B and C will not affect any files.

Note:

 

  1. By default, the ln command establishes a hard link.
  2. -S is not the meaning of soft, but the meaning of symbolic. Therefore, it should be a symbolic link, rather than a commonly used link. It should be corrected in the future.

 

Explanation 3

Use ln existing-file new-link for hard links. When you have multiple names for the same file, each name is called the hard link of the file. That is, there are multiple file names for the same I node number. Using RM to delete a file name does not affect other names and file content.

A soft link is a small pointer file that uses ln-s real-file PTR-File

It can operate directories and other file systems, but hard links won't work. Generally, commands operate on the objects pointed to by pointers, while RM and MV commands only operate on soft links. You can only see soft connections with LS-L.

Symbolic Link: Soft link that points to the pointer to the directory where the file is located. Deleting the file does not affect the original file.

Hard link: point to the inode node of the file to increase the reference count of the original file. If the reference count is zero, the original file is deleted.

Article from http://286233953.blog.163.com/blog/static/10400031200810692614796/

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.