Reputation: 49
I'm making a shell script that identifies hard links to a directory, but I need to know the source file. example:
Ln origen1.txt destino1.txt
Ln origen1.txt destino2.txt
Ln origen1.txt destino2.txt
The output should be origen1.txt, because this is the source file for other hard links. This should be in bash. I need help, Thank you.
Upvotes: 1
Views: 1635
Reputation: 123570
Like people have pointed out, hard links are all equivalent. However, you can use find
to find all the hard links of a file:
find / -samefile destino2.txt
It won't say which link was the first one, but it will tell you all the possible candidates.
Upvotes: 1
Reputation: 312263
You can't. If you have a file file1
, and you create a hardlink to it using ln
:
ln file1 file2
Then the two files are indistinguishable. A "hard link" is really just the same thing as a normal file entry; it just happens to point to the same file as another entry. You can remove either one and you're back to having a single "hard link" to the file.
Upvotes: 3