I am trying to make a script which will delete files older than a year.
This is my code:
#!/usr/bin/perl
$files = ".dat|.exe";
@file_del = split('|',$files);
print "@file_del";
$dates = "365|365|365|365";
@date_del = split('|',$dates);
if($#date_del == 0){
for $i (@file_del){
my $f = `find "/Users/ABC/Desktop/mydata" -name *$i -mtime +date[0]`;
print "$f";
}
}
else{
for $i (0..$#file_del){
my $f = `find "/Users/ABC/Desktop/mydata" -name *$file_del[$i] -mtime +$date_del[$i]`;
print "$f";
}
}
Issues I am facing:
- It is not detecting .txt files, otherwise .data,.exe,.dat etc it is detecting.
- Also -mtime is 365. But a leap year(366 days) I have to change my script.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…