#!/usr/bin/python import sys import os # TIP: rm $(md5sum ./* | duplicate -) # that will remove all duplicate files in a directory def main(): if len(sys.argv) != 2: print("Usage: duplicate "); return 0 file = sys.argv[1] try: if file == '-': handle = sys.stdin else: handle = open(file) except IOError: os.write(2,"Couldn't open " + file + " for reading\n") return(0) filelist = [] md5list = [] indexlist = [] line = handle.readline() while line != '': ls = line.split() filelist.append(ls[1]) md5list.append(ls[0]) line = handle.readline() handle.close() for x in xrange(0,len(md5list)): c = md5list.index(md5list[x]) indexlist.append ( (filelist[x],c) ) for x in xrange(0,len(indexlist)): if x != indexlist[x][1]: print(filelist[x]) main()