Skip to content

Instantly share code, notes, and snippets.

@jab416171
Created October 22, 2015 20:08
Show Gist options
  • Save jab416171/02744924924c49b7e29c to your computer and use it in GitHub Desktop.
Save jab416171/02744924924c49b7e29c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
filename = sys.argv[1]
token = sys.argv[2]
def set_contains(set, token):
for item in set:
if token in item:
return True
return False
def get_first_not_matching(set, token):
for item in set:
if token not in item:
return item
return ""
with open(filename) as lines:
files = set()
for line in lines:
if line == "\n":
file_to_delete = ""
if set_contains(files, token):
file_to_delete = get_first_not_matching(files, token)
if len(file_to_delete) > 0:
print file_to_delete.rstrip('\n').replace(" ", "\ ")
files = set()
else:
files.add(line)
USAGE:
1. fdupes -rq . > "fdupes-$(date +"%Y%m%d%H%M%S").txt"
2. token="./the/prefix"; ./duplicatefiledeleter.py fdupes-* "$token" | while read line; do rm -f "$line" > /dev/null; done; rm -f fdupes-*;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment