![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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, |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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:
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
no my unix system does not support the ls -lT command for time...
is there anything else. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|