#!/usr/bin/perl # # dfrm [-f] [dir]... # # Search all the listed directories for backup files, and unlink them. # The -f option means "forever", where the number is the number of # seconds between passes; the default is just once. If no directories # are listed, a canned list is used. $delay = 0; @dir = (); for (@ARGV) { if (/^-f$/) { $delay = 10; } elsif (/^-f(\d+)$/) { $delay = $1; } else { push(dir,$_); } } if (!@dir) { for $d ('.', '..', $ENV{'HOME'}) { if (-d $d) { if (open(L,"ls $d |")) { for $e () { next if ($e =~ /^\./); chop $e; $p = "$d/$e"; if (-d $p) { push(@dir,$p); } } } } } } print "Dirs: @dir\n"; again: for $d (@dir) { if (opendir(D,$d)) { while ($e = readdir(D)) { if ($e =~ /-$/) { print "Del: $d/$e\n"; unlink("$d/$e"); } } } } system 'df .'; if ($delay) { sleep $delay; goto again; } exit 0;