How can we get time from a unix file?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How can we get time from a unix file?
# 1  
Old 02-27-2008
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,
# 2  
Old 02-27-2008
Tools 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
# 3  
Old 02-27-2008
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.
Smilie
# 4  
Old 02-27-2008
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  
Old 02-28-2008
no my unix system does not support the ls -lT command for time...
is there anything else.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

2. Shell Programming and Scripting

How to send a file in UNIX through email which is created only 15 minutes before the current time?

I wanted to send an email to the client whenever there is failed record created in a /feed/HR-76/failed folder after processing of feed file. I can find out with the help of below script that what is the new file created but that file didn't make just 15 minutes before. ... (1 Reply)
Discussion started by: puneetkhullar
1 Replies

3. Shell Programming and Scripting

How to pick system time of the file placed on UNIX?

Hi ,I got one data file from external source and I have to load it in database through sql loader. I want to add 2 columns in database,one is file name and one is time of the file received on server. -rwxr-x--- 1 user user 238 Jun 03 16:32 90936264971326030616.ctr From above case,... (21 Replies)
Discussion started by: Ruchika
21 Replies

4. UNIX for Dummies Questions & Answers

File creation time in UNIX

Hi All, Can any one help how to long list today's files in unix.i.e files which are have been created today should be able to "ls -ltr" .I should be able to apply the "ls -ltr" command on today's files(should not include all the files which were there in the directory). Thanks in advance!!! (3 Replies)
Discussion started by: Balasankar
3 Replies

5. UNIX for Dummies Questions & Answers

Delete Unix/Linux file at a specific time in future.

Hi, I was wondering if there is a command to delete a file in the future. For example: If I create a file named unix.lst using the vi editor, but after I create it, what command will be suitable to delete "unix" files from the system at 13:40 military time with no log file. I was going to... (3 Replies)
Discussion started by: abhi7514
3 Replies

6. UNIX for Dummies Questions & Answers

About Unix File creation time

Hello, I registered and recreated this thread because everywhere we can see "It's not possible to get the file creation time in UNIX fs". This is not true any more with Ext4! Unfortunately, there is not user-level tools that allow you to read those information. You have to use a low level tool... (4 Replies)
Discussion started by: gaellafond
4 Replies

7. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies

8. Shell Programming and Scripting

Unix File creation time

IS there any command to find the file creation time in Unix. (2 Replies)
Discussion started by: tinivt
2 Replies

9. Shell Programming and Scripting

Listing the creation date/time of a file in unix

Hi, I need the unix command which returns only the file name and its creation date/time in unix. I tried ls -l <filename>. But that is giving other details also which I do not want. Could anyone help me out? Thanks. (6 Replies)
Discussion started by: unipepper
6 Replies
Login or Register to Ask a Question