cs87
cs87

Reputation: 37

Want to show create time for some files.

I was writing perl and run it in window system pretty good . But when i transfer the perl script from windows system to Linux. And run in Linux system , i get wrong date/time. Need some help. Thanks.

The source code in Perl

   if (($file =~ m/(\d)(\S+)\.csv/) && ($flag == 0))  
            {
                    open(para_file,$file);
                    $datetime_string = ctime( stat($file)->ctime );

                    while ($line=<para_file>)
                    {
                    if ($line =~ /0\,170\,16\,/) 
                            {
                                    $cal = $cal + 1;
                            }
                    }
                            push(@data,"$cal");
                            push(@data,"$datetime_string");
             }            

$file will be my file name. The windows date & time on create are correct but don't understand why in LINUX it give me the wrong date & time.

Output of generation , from windows

9023-0 50000 5111 10.22 Mon Jul 21 17:44:38 2014
9023-2 100000 23251 23.25 Fri Apr 11 10:12:19 2014
9024_AHG 5000 0 0.00 Thu Nov 27 15:28:55 2014

Output of generation , from linux

9023-0 50000 5111 10.22 Thu Jul 30 16:45:25 2015
9023-2 100000 23251 23.25 Thu Jul 30 16:45:25 2015
9024_AHG 5000 0 0.00 Thu Jul 30 16:45:25 2015

Upvotes: 0

Views: 79

Answers (1)

Sobrique
Sobrique

Reputation: 53478

The problem here isn't what you're doing, it's that you misunderstand what ctime is. Linux filesystems record a change time not a creation time.

mtime denotes modification of file content. ctime denotes modification of attributes. As a result, they may well be the same number.

However what you cannot get is "create time" because the EXT filesystem doesn't record it. (Other filesystem formats may - NTFS for example - but I'm not sure I'd suggest using NTFS on a Linux box!)

Upvotes: 4

Related Questions