Verifying Hard Link Creation
Checking the Inode Number
One way to verify the creation of a hard link is to check the inode number of the files. The inode number is a unique identifier for a file in the Linux file system. If two files have the same inode number, they are hard links pointing to the same file data.
You can use the ls -i
command to display the inode number of a file:
$ ls -i file1.txt file2.txt
12345 file1.txt
12345 file2.txt
In the example above, both file1.txt
and file2.txt
have the same inode number 12345
, indicating that they are hard links.
Checking the Hard Link Count
Another way to verify the creation of a hard link is to check the "hard links" count for the file. The ls -l
command displays the number of hard links for each file.
$ ls -l file1.txt file2.txt
-rw-rw-r-- 2 user user 0 Apr 12 12:34 file1.txt
-rw-rw-r-- 2 user user 0 Apr 12 12:34 file2.txt
In the output above, you can see that both file1.txt
and file2.txt
have "2" hard links, indicating that they share the same inode.
graph LR
A[file1.txt] -- Hard Link --> B[file2.txt]
C[Inode 12345] -- Shared --> A
C -- Shared --> B
By checking the inode number and the hard link count, you can verify that the hard link has been successfully created in Linux.