专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>perl>

perl实现删除半年以前的文件

百度收藏 QQ搜藏

请指教高手:用perl如何删除半年以前的文件?
不着急,写了一个perl脚本,主要是用了Date::Manip模块,代码如下:

#!/usr/bin/perl

use strict;
use Date::Manip;

my $date1 = &DateCalc("today","-180 days", 0);
my @temp = stat("file.txt");
my $date2 = $temp[8];

my $flag = &Date_Cmp($date1,$date2);
if($flag < 0)
{
   print "$date1 is earlier than $date2!\n";
}
elsif($flag == 0)
{
   print "the two dates are identical!\n";
}
else
{
   print "$date2 is earlier than $date1!\n";
}
exit 0;

当然用shell更简单啦
先看是有哪些文件
$find / -mtime +180 -exec ls {} \;
然后删除掉
$find / -mtime +180 -exec rm {} \;

上一篇:查询PERL模块安装的perl脚本 下一篇:perl脚本监控windows主机

power by soyo123 2007-2008