#!/usr/bin/perl -w use strict; use Getopt::Std; use File::Basename; use Time::localtime; use File::stat qw(:FIELDS); $|=1; my %opts; my $me = basename($0); getopts('amspuh', \%opts); do { usage();exit } if exists $opts{h}; usage() if (@ARGV < 1); if (keys %opts) { for my $file (@ARGV) { do { warn "File: $file not found\n"; next } unless -f $ARGV[0] +; print "\nFile: $file\n"; stat($file) or do {warn "Cannot get statistics on $file", $!;n +ext }; SWITCH:for (keys %opts) { /^a$/i && do { print "\tatime: ", ctime($st_atime +), "\n"; next SWITCH }; /^m$/i && do { print "\tctime: ", ctime($st_mtime +), "\n"; next SWITCH }; /^s$/i && do { print "\tsize: $st_size\n"; next SWITCH }; /^p$/i && do { my $fmode = sprintf "%o", $st_mode +; $fmode =~ s/^.{3}(.{3}$)/$1/; print "\tmode: $fmode\n" ; next SWITCH }; /^u$/i && do { printf "\towner: %s\n", ($^O =~ /^ +MSW/) ? "Unsupported in MS Windows" : (getpwuid $st_uid)[0]; next SWITCH }; } } } else { do_all($_) foreach (@ARGV) } sub do_all { my $file = shift; print "\nFile: $file\n"; stat($file) or do {warn "Cannot get statistics on $file", $!;next +}; print "\tatime: ", ctime($st_atime), "\n"; print "\tctime: ", ctime($st_mtime), "\n"; print "\tsize: $st_size\n"; my $fmode = sprintf "%o", $st_mode; $fmode =~ s/^.{3}(.{3}$)/$1/; print "\tmode: $fmode\n" ; printf "\towner: %s\n", ($^O =~ /^MSW/) ? "Unsupported in MS Windows" : (getpwuid $st_uid)[0]; } sub usage { die <<EOM Usage: $me [-a] [-s] [-m] [-p] [-u] [-h] file -a Print files access time. -m Print files modify time. -s Print files size in bytes. -p Print files permissions(mode). -u Print files owner user id. -h Print help(this screen). Any combination of options may be used with the exception of -h The help command is exclusive. If no options are present on the command line all statistics will be returned. EOM }

In reply to File Statistics by sweetblood

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.