René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Removing same sized files with perl | ||
The following finds .txt files that have the same size and removes all but one per size.
use strict; use warnings; my @files = <*.txt>; my %file_sizes; foreach my $file (@files) { push @{$file_sizes{(stat ($file))[7]}}, $file; } foreach my $size (keys %file_sizes) { my @same_sized_files = @{$file_sizes{$size}}; print join "-", @same_sized_files; unlink @same_sized_files[1 .. $#same_sized_files]; print "\n"; } |