1833356 Members
3129 Online
110051 Solutions
New Discussion

Timestamp of a file

 
SOLVED
Go to solution
Ronelle van Niekerk
Regular Advisor

Timestamp of a file

Is it possible to determine down to the seconds when a file was last modified?

Or is the timestamp of a file only donw to minutes?

-Ronelle
rm -r /it/managers
4 REPLIES 4
Rajeev  Shukla
Honored Contributor

Re: Timestamp of a file

You can nail down to seconds level too. But for that you'll have to write a C program and use stat() function.

Cheers
Rajeev
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Timestamp of a file

Hi Ronnelle,

You can use the same stat function in perl to get the modified time.

use File::stat;
printf "Enter the path:";
$file = ;
chop $file;
$handle = stat($file);
$TIME = scalar localtime $handle->mtime;
printf "%s\n",$TIME;

If you take out scalar localtime, then you will get the time in seconds since epoch. You can use it to calculate whatever you want.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Ronelle van Niekerk
Regular Advisor

Re: Timestamp of a file

Thank you both.

Sridhar, I have used your script and it works.
rm -r /it/managers
john korterman
Honored Contributor

Re: Timestamp of a file

Hi,

just for the record, the old cpio trick:
# echo |cpio -o 2>/dev/null|cpio -ivt 2>/dev/null

regards,
John K.
it would be nice if you always got a second chance