Skip to content

Instantly share code, notes, and snippets.

@jostmart
Created May 22, 2017 08:45
Show Gist options
  • Save jostmart/f44d592a893df27c9ff4ebbe21a1058a to your computer and use it in GitHub Desktop.
Save jostmart/f44d592a893df27c9ff4ebbe21a1058a to your computer and use it in GitHub Desktop.
slette.pl (jonas skript)
#!/usr/bin/perl
#
# Takk Jonas :)
#
use strict;
use File::Path;
my $folder=$ARGV[0];
my $antall = 1;
opendir (DIR,$folder);
my @dirs = readdir(DIR);
my %re_hash;
foreach my $ret_re (@dirs){
if (-f $folder . "/" . $ret_re && $ret_re =~ m/^[^\.]/){
$re_hash{$ret_re} = (stat($folder . "/" . $ret_re ))[9];
}
}
closedir(DIR);
foreach my $fil ( sort { $re_hash{$b} <=> $re_hash{$a} } keys %re_hash) {
if ($antall-- < 0){
unlink $folder . "/" . $fil;
}
}
@jostmart
Copy link
Author

13:53 jeg forstår ikk hva den koden der gjer
13:53 va?
13:53 slette.pl ?
13:53 ahh
13:53 ja
13:53 joda
13:54 først lager man seg en hash av filnavn og timestamps
13:54 så looper man gjennom de $antall filer som skal beholdes
13:54 og sletter resten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment