Hard link and soft link (1)

Source: Internet
Author: User
Tags symlink

Disclaimer: This article is reposted from http://keren.blog.51cto.com/720558/170979;. There are two types of links in the Unix directory-hard links and symbolic links. A hard link itself is a directory item (such as a file name + index node number). You can associate a file name with the file location. A symbolic link is also called a soft link, A file that stores a string. This string can be used to modify the path name during path name resolution. Suppose that the file is represented by an index node ---------------------------------------------------- the directory items correspond to a single link, but an index node may have several link targets (corresponding to several directory items ), therefore, the index node contains a count of the number of links linked to the index node. When open () is used to create a new file, the operating system creates a new directory item and assigns an idle index node to indicate the file. Figure 1 Figure 1 shows the directory item of the name1 file under/Dira. The index node is 12345 and there is a link. Its first data block is 23567. The file is small and all content is contained in a block. (1) create a hard linkYou can use the command ln or function Link () to create a link for the file. # Include <unistd. h> int Link (const char * path1, const char * path2); the above operation is an existing file specified by path1 (such as/DRIA/name1) create a new directory item. The file is located in the directory specified by path2 (for example,/drib/name2), and the corresponding index node link count is added. No additional disk space is used. 2: Figure 2 (2) create a symbolic linkA symbolic link is a file that contains the name of another file or directory. Referencing the Symbolic Link name will enable the operating system to locate the index node corresponding to the link, knowing that a hard indirect and a real file will eventually be encountered. If the system does not find the file after a period of time, it will give up and return the eloop error. You can use the ln command with the option-S or function symlink () to create a symbolic link. # Include <unistd. h> int symlink (const char * path1, const char * path2); here path2 is a newly created link, and the new link points to path1. 3: Figure 3 here, the symbolic link uses a new index node (13579), which contains information indicating that it is a symbolic link. A symbolic link requires at least one data block (such as 15213). The data block contains the name of the file to be linked by/dirb/name2, Which is/Dira/name1.

This article from the "indifferent to Mingzhi, quiet to far" blog, please be sure to keep this source http://keren.blog.51cto.com/720558/170979

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.