Content of the Perl File:
use File::stat;
my $sb = stat("test.txt");
print "Size: ".$sb->size."\n";
print "mtime in unreadable format:". $sb->mtime."\n";
$mtime=$sb->mtime;
my @systime = localtime($mtime) ;
my $str = strftime( "%a %b %e %H:%M:%S %Y", @systime );
print "mtime in readable format:".$str."\n";
print "chmmod :".$sb->mode ."\n";
printf "Permissions are %04o\n", $sb->mode & 07777;
print "ctime :". $sb->ctime."\n";
#ctime can also be converted into correct format similarly as did for mtime
We can access all the other file attributes given below by using $sb->needed file attribute as done for attribtes like mtime,ctime.
- 0 dev device number of filesystem
- 1 ino inode number
- 2 mode file mode (type and permissions)
- 3 nlink number of (hard) links to the file
- 4 uid numeric user ID of file's owner
- 5 gid numeric group ID of file's owner
- 6 rdev the device identifier (special files only)
- 7 size total size of file, in bytes
- 8 atime last access time in seconds since the epoch
- 9 mtime last modify time in seconds since the epoch
- 10 ctime inode change time in seconds since the epoch (*)
- 11 blksize preferred block size for file system I/O
- 12 blocks actual number of blocks allocated
This was reffered from http://perldoc.perl.org/functions/stat.html
Output :
G:\perl_programs>perl perl_size.pl
Size: 42
mtime in unreadable format:1310916921
mtime in readable format:Sun Jul 21:05:21 2011
chmmod :33206
Permissions are 0666
ctime :1310916921
G:\perl_programs>
No comments:
Post a Comment