Get timestamp using perl script

Posted on 2010-01-06
Last Modified: 2012-05-08
I am new to perl scripting,  i need a a perl script to copy a directory from remote machine to my local machine and print the filenames and its timestamp in the directory and its subdirectories which is been copied to local machine.  this perl script  should work both in unix and windows.
Question by:frnxx
    LVL 4

    Accepted Solution

    This perl print timestamp, use this code to you.
    #!/usr/bin/perl -w
    @Month_name = ( "January", "February", "March", "April", "May", "June",
      "July", "August", "September", "October", "November", "December" );
    ( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
    printf  "%02d:%02d:%02d %02d %s %04d\n",
      $hour, $min, $sec, $day, @Month_name->[$month], $year+1900 ;
    LVL 28

    Assisted Solution

    Do you want the current timestamp or the mtime or ctime of the file?

    If you need the file's timestamp, then look at the stat function.

    Here's a clean way to output a formatted timestamp.

    use strict;
    use warnings
    use POSIX;
    print strftime('%H:%M:%S %d %B %Y', localtime);

    Open in new window

    LVL 5

    Assisted Solution

    To get the timestamp of a file in $file use the following code:

    use File::stat;
    use Time::localtime;
    $date_string = ctime(stat($file)->mtime);
    print "Timestamp of file $file: $date_string\n";

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now