What is Linux soft link and Linux hard link _linux

Source: Internet
Author: User

There are two kinds of Linux links, one is called hard link (Hard link), the other is called soft link (symbolic link). By default, the LN command produces a hard link.

A, [hard link]--> refers to through the index node to connect. In a Linux file system, a file stored in a disk partition is assigned a number, called an index node number (Inode index), regardless of its type. In Linux, multiple file names point to the same index node. Generally this connection is a hard connection. The effect of a hard connection is to allow a file to have multiple valid pathname, so that users can build hard connections to important files to prevent "accidentally delete" functionality. The reason for this is as described above because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the index node itself and other connections, and only when the last connection is deleted will the file's data block and directory connections be freed. That is, the condition that the file is actually deleted is that all of the hard connection files associated with it are deleted.

Syntax:ln "source file" "Hard Connection File"

[Root@centos-study pc]# test1
[root@centos-study pc]# ll total
0
-rw-r--r--1 root 0 Dec 00:34 t Est1
[root@centos-study pc]# ln test1 test2
[root@centos-study pc]# ll total
0
-rw-r--r--2 Root 0 De C 00:34 test1
-rw-r--r--2 root 0 Dec 00:34 test2
[Root@centos-study pc]# 

If you delete the test1 above, the test2 will continue to exist and the data will remain

[Root@centos-study pc]# rm test1
rm:remove Regular empty file ' test1 ' y
[root@centos-study pc]# ll Total
0
   -rw-r--r--1 root 0 Dec 00:34 test2

Hard Connection Summary:

(1) Hard linked inode is the same

(2) can only be created on a file, not applied to the directory

(3) cannot cross partition

Second, soft link

Equivalent to a shortcut in Windows, because a soft connection creates a file that is a separate new file, so it takes up indoe and block

The system has a/root/crontab, it is/etc/crontab soft connection, if deleted the source file/root/crontab, then/etc/crontab this file's data also cannot view, just like Windows inside the desktop shortcut, The source file has been deleted and the shortcut is invalid.

Syntax: ln-s "source file or directory" "Software chain name"

Fan Lee:

[Root@centos-study pc]# ll total
0
-rw-r--r--1 root 0 Dec 00:34 test2
[Root@centos-study, pc]# ln-s t Est2 test3
[root@centos-study pc]# ll total
0
-rw-r--r--1 root root 0 Dec 00:34 test2
lrwxrwxrwx 1 roo T-Root 5 Dec 00:42 test3-> test2
[Root@centos-study pc]# 

If I delete the source file, then the soft connection file will not be able to view the data in it, and it will always flash when I see the soft connection.

Soft Connection Summary:

(1) can be applied to the directory

(2) can cross file system

(3) does not increase the number of links to linked files

(4) The total number of characters contained in the specified absolute path size

(5) has its own inode number

(6) Permissions do not matter

Third, summary

The above is the entire content of this article, I hope to help you learn.

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.