Skip to content

Instantly share code, notes, and snippets.

@dirkakrid
Forked from filipenf/lndupes.py
Created March 25, 2017 12:46
Show Gist options
  • Save dirkakrid/7e6f98f200583343f793d4419af0da89 to your computer and use it in GitHub Desktop.
Save dirkakrid/7e6f98f200583343f793d4419af0da89 to your computer and use it in GitHub Desktop.
Reads fdupes(-r1) output and create relative symbolic links for each duplicate
#!/usr/bin/env python
# Reads fdupes(-r -1) output and create relative symbolic links for each duplicate
# usage: fdupes -r1 . | ./lndupes.py
import os
from os.path import dirname, relpath, basename, join
import sys
lines = sys.stdin.readlines()
for line in lines:
files = line.strip().split(' ')
first = files[0]
print "First: %s "% first
for dup in files[1:]:
rel = os.path.relpath(dirname(first), dirname(dup))
print "Linking duplicate: %s to %s" % (dup, join(rel,basename(first)))
os.unlink(dup)
os.symlink(join(rel,basename(first)), dup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment