Softlink and Hardlink under Linux

Source: Internet
Author: User

There are two types of links in Linux: Hard links and soft links (soft link), and soft links called Symbolic links (symbolic link)

To create a command:
Ln-s Softlink destfile/directory #建立软连接
ln hardlink destfile #建立硬连接

Inode
In a Linux system, the kernel allocates an inode for each newly created file, each with a unique inode number, and we can simply interpret the inode as a pointer that will always point to the specific storage location of the file. File attributes are stored in the inode, and when the file is accessed, the inode is copied to the inside to enable quick access to the file. The system locates each file through an inode.

Hard link
A hard link is actually a pointer to the inode of the source file, and the system does not redistribute the inode for it. Hard connections do not build new inode, hard connections No matter how many, are pointing to the same inode node, but the new one will increase the number of node connections, as long as the node connection number is not 0, the file exists, regardless of whether you delete the source files or connected files. As long as there is a existence, the file exists (in fact, the concept of reference counting). When you modify the source file or any one of the connection files, the other files will be changed synchronously.

Soft links (soft link)
Soft links The most intuitive explanation: equivalent to the Windows system shortcut, is a separate file (has a separate inode, regardless of the source file inode), the content of the file is the source file path pointer, through the link can access to the source file. So delete the soft link file has no effect on the source file, but delete the source file, the soft link file will not find the file to point to (You can analogy Windows shortcut, you click the shortcut can access a file, but delete the shortcut, no effect on the source file).

Difference

    1. Soft links and source files do not have the same permissions, and the hard links are exactly the same as the source file operation permissions.
    2. Soft links can cross file systems (partitions), and because of inode limitations and the ability of the file system to unload, hard connections do not allow cross-file systems.
    3. A soft connection can connect to a file name that does not exist, and a hard link is not available.
    4. A soft connection can connect to a directory, and a hard link cannot.

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.