Created
November 8, 2009 09:06
-
-
Save simonw/229186 to your computer and use it in GitHub Desktop.
Python script for telling if two files are hard links to the same thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"is_hard.py - tell if two files are hard links to the same thing" | |
import os, sys, stat | |
def is_hard_link(filename, other): | |
s1 = os.stat(filename) | |
s2 = os.stat(other) | |
return (s1[stat.ST_INO], s1[stat.ST_DEV]) == \ | |
(s2[stat.ST_INO], s2[stat.ST_DEV]) | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print "Two arguments required" | |
else: | |
if is_hard_link(sys.argv[1], sys.argv[2]): | |
print "Hard link confirmed" | |
else: | |
print "Those are different files, no hard link" |
It works for me (at least on Windows 7)
In Python 3 the is_hard_link
could be replaced with os.path.samefile
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not work properly on windows. Returns false positives.