lunedì 24 maggio 2010

Stat command in Perl (Unix/Linux)

This perl script execute a stat of a file in UNIX/LINUX environment and accept in input file name with absolute path. It shows various file info and atime, mtime and ctime.

#!/usr/bin/perl -w

#
# stat.pl
#

($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($ARGV[0]);

print("dev = $dev\n");
print("ino = $ino\n");
print("mode = $mode\n");
print("nlink = $nlink\n");
print("uid = $uid\n");
print("gid = $gid\n");
print("rdev = $rdev\n");
print("size = $size\n");
print("atime = $atime\n");
print("mtime = $mtime\n");
print("ctime = $ctime\n");
print("blksize = $blksize\n");
print("blocks = $blocks\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($ctime);
$year = $year + 1900;
$month = $month + 1;
printf(" ctime $year/$month/$day $hr:$min:$sec\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($mtime);
$year = $year + 1900;
$month = $month + 1;
printf(" mtime $year/$month/$day $hr:$min:$sec\n");
($sec, $min, $hr, $day, $month, $year, $day_Of_Week, $julianDate, $dst) = localtime($atime);
$year = $year + 1900;
$month = $month + 1;
printf(" atime $year/$month/$day $hr:$min:$sec\n");

Stay connected.


Nessun commento:

Posta un commento

Check first quarter 2024

 Hi all Today, 1st May I'll check my 2024 goals. This is the first time I check it. For me it's a good way to reach more objective p...