From 9a0b263b7fc9d43e6acd16729ebfc2120ae501d6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 22 Dec 2010 09:04:38 +0000 Subject: Add --remove option. --- debian/changelog | 6 ++++++ dupfiles | 10 ++++++++++ dupfiles.1 | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index df2a680..76a87d2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +dupfiles (5.1) squeeze; urgency=low + + * Add --remove option. + + -- Lars Wirzenius Wed, 22 Dec 2010 09:04:17 +0000 + dupfiles (5) squeeze; urgency=low * Use python-ttystatus for progress reporting. diff --git a/dupfiles b/dupfiles index 8c06c3d..3d9e8db 100755 --- a/dupfiles +++ b/dupfiles @@ -197,6 +197,12 @@ def make_hardlinks(duplicates): os.link(canonical, pathname) +def remove_all_but_one(duplicates): + keep = duplicates.pop() + for pathname in duplicates: + os.remove(pathname) + + def report(duplicates): sys.stdout.write('\n'.join(duplicates)) sys.stdout.write('\n\n') @@ -208,6 +214,8 @@ def main(): help='hardlink duplicate files to each other') parser.add_option('--progress', action='store_true', help='report progress') + parser.add_option('--remove', action='store_true', + help='remove all but one copy of identical files') opts, args = parser.parse_args() @@ -218,6 +226,8 @@ def main(): for duplicates in dupfinder.duplicates(): if opts.make_hardlinks: make_hardlinks(duplicates) + elif opts.remove: + remove_all_but_one(duplicates) else: report(duplicates) diff --git a/dupfiles.1 b/dupfiles.1 index 1bcf159..ee66d9b 100644 --- a/dupfiles.1 +++ b/dupfiles.1 @@ -20,6 +20,7 @@ dupfiles \- find identical files and optionally hardlink them .B dupfiles .RB [ --make-hardlinks ] .RB [ --progress ] +.RB [ --remove ] .RI [ file ]... .SH DESCRIPTION .B dupfiles @@ -43,7 +44,10 @@ Report progress while program is running. .BR --make-hardlinks Instead of reporting files that have been found, make sure all names point at the same content. -FIXME. +.TP +.BR --remove +Remove all but one copy of identical files. +The copy that gets kept is chosen arbitrarily. .SH EXAMPLE To find all duplicate packages in Debian and Ubuntu: .IP -- cgit v1.2.1