cd test3/
touch file{1,2,3,4,5}
ls -l
checkiffileaccess1.pl
#!/usr/bin/perl -w
use strict;
my @flist = `ls -A file*`;
#my @flist = `ls -A file{1,2,3,4,5}`;
foreach(@flist)
{
chomp;
print $_\n;
#stat($_);#returns an array of 13 elements, atributes. In these variable you can find the modification time and access time.
my @stats = stat($_);
(my $atime, my $mtime) = ($stats[8], $stats[9]);
print "Access time: $atime - Mod Time: $mtime";
#expr $atime $mtime; #return the difference between the 2 values;
#foreach (@stats)
#{
# print "$_\n";
#}
if($atime = $mtime != 0)
{
print "File $_ has been accessed \n";
my $new_name = "$_".".old";
rename($_,$new_name);
}
}
#end
file file5 # returns empty if the file is empty.
echo "test" >> file5
file file5 # return ASCII text
ls -l --time=atime file1#access file
ls-i file1#modification file1
No comments:
Post a Comment