Created
August 19, 2016 19:04
-
-
Save filipenf/e9901883d66b8da65c151cf674e5f2a9 to your computer and use it in GitHub Desktop.
Reads fdupes(-r1) output and create relative symbolic links for each duplicate
This file contains 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 | |
# 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) |
Based on the improved version by @jeroenvermeulen, I made this Python 3 compatible by fixing the print()
s.
https://gist.github.com/oh2fih/810928a48b4b71d0b11f4bb1872dd3d2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @filipenf, thanks for this great script!
I improved your script, because it did split wrong when there were spaces one of the filenames.
Updated version: https://gist.github.com/jeroenvermeulen/a1667c60dc159c8f0487acee2cca256f