I would like to know if it is possible identify whether a file (or link) is a hardlink or not, on Linux. For instance, If I created:
dd if=/dev/urandom bs=1024 count=10000 of=file_10MB conv=notrunc
ln file_10MB file_10MB_link1
I would like to create a check function, that could be used like this:
if is_hardlink("file_10MB_link1"):
pass
How can I use Python to check if a file is a hardlink?
No, it's not possible. There's nothing that distinguishes the original file from the hard link. They're just two names that refer to the same inode number, which represents the file contents.
You can use the code in Anthony Sottile's answer to tell if the file has multiple links to it, but you can't tell which is the original.