& Amp; bull; inode I have to talk about inode before discussing the Linux system links. 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...
• 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