Hard Link in File System

Table of Contents

1 什么是硬链接

In computing, a hard link is a directory entry that associates a name with a file on a file system.


Figure 1: An illustration of the concept of hard linking.

In the figure 1, two hard links, named "A.TXT" and "B.TXT", point to the same physical data.


1.1 什么是软链接

Symbolic link or soft link, unlike hard link, points to filename, not file data itself.

2 创建和检测硬链接

All files are hard links, with link counts of at least 1.

2.1 On MS Windows

Hard links can be created using the mklink /H command on Windows NT 6.0 and later systems (such as Windows Vista), and in earlier systems (Windows XP, Windows Server 2003) using fsutil.exe hardlink create.

可以用命令 fsutil.exe hardlink list 来检测某个文件有哪些硬链接。如:

C:\windows\system32>fsutil.exe hardlink list C:\Windows\System32\notepad.exe

2.2 On Unix-like system

Hard links can be created using the ln or link command-line utilities on Unix-like system.

用命令 ls -l 可以得到文件硬链接的引用数。
用命令 ls -i 可以得到文件inode号码(同一文件的inode号码相同)。
用命令 find . -inum NUM 可以得到当前目录下inode号码为NUM的所有文件。

用命令 find . -samefile file1 可以得到和文件file1硬链接到同一文件的所有文件。

3 Limitations of hard link

  1. Many modern operating systems do NOT allow hard links to directories.
  2. Hard links can be created to files only on the same volume.

Author: cig01

Created: <2011-07-23 Sat 00:00>

Last updated: <2015-08-29 Sat 12:59>

Creator: Emacs 25.1.1 (Org mode 9.0.7)