The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 08:23 AM
Linux Going Big Time and Prime Time Against Windows, UNIX (WSJ) (Addict 3D) iBot UNIX and Linux RSS News 0 06-21-2007 01:10 PM
How To Provide Time Sync Using Nts-150 Time Server On Unix Network? pesty UNIX for Advanced & Expert Users 2 03-21-2007 11:20 PM
Unix File creation time tinivt Shell Programming and Scripting 2 01-23-2007 03:27 AM
Listing the creation date/time of a file in unix unipepper Shell Programming and Scripting 6 02-15-2006 04:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 4
Question How can we get time from a unix file?

Hi,
Could you please help me to get file's time stamp in dd-mm-yyyy format using shell script.
When I do ls -l , it gives date and month of modification.
Is there any easy way of getting the year ?
Please help me.

I want it to be written to the file in dd-mm-yyyy format.

Thanks,
Reply With Quote
Forum Sponsor
  #2  
Old 02-27-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Cool coded in perl, with a few other things

There are actually 3 dates/times stored - access, modify, create. From the request, it seems like you want the modify. Others shown to demonstrate how they could be used. Therefore, several lines in the middle could be removed.

Code:
> cat filestatus 
#! /bin/perl

#this holds the filename being researched
$filein="alarm1";

($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
 $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($filein);

$atime_f = localtime($atime);
$mtime_f = localtime($mtime);
$ctime_f = localtime($ctime);

print "last access = $atime_f \n"; 
print "last modify = $mtime_f \n";
print "file create = $ctime_f \n";
print " \n";

($day,$month,$year) = (localtime($mtime))[3,4,5];
#sprintf is built-in function for perl
$mtime_x = sprintf("%02d-%02d-%04d", $day, $month +1, $year + 1900);
print "formatted last modify = $mtime_x \n";
Quote:
> filestatus
last access = Wed Feb 27 10:43:46 2008
last modify = Wed Feb 27 10:43:49 2008
file create = Wed Feb 27 10:43:49 2008

formatted last modify = 27-02-2008
Reply With Quote
  #3  
Old 02-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 4
Thanks for the script ..is there anything you can do in Unix scripting and also i need the create timestamp to be copied in file.
Reply With Quote
  #4  
Old 02-27-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
If your system's version of ls supports the -T option, then ls -lT will give you what you want

-T, --full-time
Display complete time information for the file, including month,
day, hour, minute, second, and year. This option has no effect
unless one of the long format (-l, -n) options is also specified.
Reply With Quote
  #5  
Old 02-28-2008
Registered User
 

Join Date: Feb 2008
Posts: 4
no my unix system does not support the ls -lT command for time...
is there anything else.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0