Linux file system links

Source: Internet
Author: User

 

• Inode

Before discussing the Linux system connection, I have to talk about inode first. Each object in the Linux file system has a unique inode index. Each inode number corresponds to one object in the file system, to view the inode number of a file or directory, use the-I option in the ls command. (Current Directory) and .. (upper-level Directories) are hard links. For example:

Root @ vrlab726-desktop :~ /Desktop # pwd

/Root/Desktop

Root @ vrlab726-desktop :~ /Desktop # ls-ial

Total 8672

6447440 drwxr-xr-x 9 root 4096.

Copy code

The inode number of the/root/Desktop directory is 6447440. Next, let's look at the inode Number of/root/Desktop/test:

Root @ vrlab726-desktop :~ /Desktop # cd test

Root @ vrlab726-desktop :~ /Desktop/test # pwd

/Root/Desktop/test

Root @ vrlab726-desktop :~ /Desktop/test # ls-ial

Total 8

7668672 drwxr-xr-x 2 root 4096.

6447440 drwxr-xr-x 9 root 4096 ..

Copy code

We can find that the inode numbers of the two are exactly the same, that is, the two are linked to the same entry on the physical disk.

• Hard link

An inode number can correspond to any number of hard links. When all hard links are deleted, the inode number will also be automatically deleted by the system, the third column of the ls-ial command is the number of hard links associated with the current inode number. The command for creating a hard link is:

Root @ vrlab726-desktop :~ /Desktop/test # touch file

Root @ vrlab726-desktop :~ /Desktop/test # echo "helloWorld"> file

Root @ vrlab726-desktop :~ /Desktop/test # more file

HelloWorld

Root @ vrlab726-desktop :~ /Desktop/test # ln file fileHardLink

Root @ vrlab726-desktop :~ /Desktop/test # ls-ial

Total 16

7668672 drwxr-xr-x 2 root 4096.

6447440 drwxr-xr-x 9 root 4096 ..

7668707-rw-r -- 2 root 11 2011-12-14 20:19 file

7668707-rw-r -- 2 root 11 2011-12-14 20:19 fileHardLink

Copy code

It can be seen that hard links all point to the same inode entry, so the occupied space is the same. However, there are two restrictions on hard links in Linux: 1. Hard links can only be linked to files, not folders. Even though they are hard links to directories created by the system, users (even root accounts) are not allowed to create hard links to directories. 2. Hard links cannot be used across file systems.

• Soft link (symbolic link)

In fact, soft links are more commonly used than hard links. Symbolic Links are a special file type. They only link to another file through file names, rather than directly linking to inode. If the target file to be linked is deleted, all soft links linked to the target file are disconnected and no longer available. The command for creating a soft connection is as follows:

Root @ vrlab726-desktop :~ /Desktop/test # ln-s file fileSoftLink

Root @ vrlab726-desktop :~ /Desktop/test # ls-ial

Total 16

7668672 drwxr-xr-x 2 root 4096.

6447440 drwxr-xr-x 9 root 4096 ..

7668707-rw-r -- 2 root 11 2011-12-14 20:19 file

7668707-rw-r -- 2 root 11 2011-12-14 20:19 fileHardLink

7668708 lrwxrwxrwx 1 root 4 2011-12-14 fileSoftLink-> file

Copy code

You can identify the symbolic link from two aspects. The first letter in the second column of ls-ial is l, and the target file in the last column contains the-> symbol.

 

Conclusion: www.2cto.com

Hard links are implemented based on inode, while soft links are implemented based on names (or paths). Hard links only allow users to create hard links to files, soft links can be linked to both files and directories. Hard links cannot be used across file systems (because inode numbers may be the same in different file systems). Soft links are implemented through paths, therefore, cross-file systems are supported.

Author Jing Si

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.