Created
October 22, 2015 20:08
-
-
Save jab416171/02744924924c49b7e29c to your computer and use it in GitHub Desktop.
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 | |
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) |
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
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