Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.