Skip to content

Instantly share code, notes, and snippets.

@poma
Created June 2, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poma/7cb88eeceede3cb59478eca09cb0d858 to your computer and use it in GitHub Desktop.
Save poma/7cb88eeceede3cb59478eca09cb0d858 to your computer and use it in GitHub Desktop.
Hard link all duplicate files generated by fdupes
import os
dupes = [];
src = open('fdupes.txt')
for fline in src:
line = fline.strip()
if line:
dupes.append(line)
else:
while len(dupes) > 0 and not os.path.isfile(dupes[0]):
del dupes[0]
if len(dupes) > 1:
base = dupes[0];
del dupes[0]
for file in dupes:
if os.path.isfile(file):
os.remove(file);
os.link(base, file)
print 'linked ' + file + ' -> ' + base
dupes = []
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment