<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/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 &lt; 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", $!;next };
        SWITCH:for (keys %opts) {
            
                /^a$/i    &amp;&amp; do {
                                    print "\tatime: ", ctime($st_atime), "\n";
                                    next SWITCH
                                };
    
                /^m$/i    &amp;&amp; do {
                                    print "\tctime: ", ctime($st_mtime), "\n";
                                    next SWITCH
                                };
                
                /^s$/i    &amp;&amp; do {
                                    print "\tsize:  $st_size\n";
                                    next SWITCH
                                };
                
                /^p$/i    &amp;&amp; do {
                                    my $fmode = sprintf "%o", $st_mode;
                                    $fmode =~ s/^.{3}(.{3}$)/$1/;
                                    print "\tmode:  $fmode\n" ;
                                    next SWITCH
                                };
    
                /^u$/i    &amp;&amp; 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 &lt;&lt;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
}

</pre></body></html>