LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to get the timestamp of a file? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-get-the-timestamp-of-a-file-405597/)

operand 01-19-2006 08:53 PM

How to get the timestamp of a file?
 
How to get the timestamp of a file on Linux?
I know two commands: "ls -l" and "stat".
Is there any other command that can get that information?

Thanks for your attention and look forward to your reply.

gilead 01-19-2006 09:10 PM

stat is the best tool to access all 3 (atime, ctime, mtime) quickly. The man page doesn't list any other tools either... There's a useful definition of these at http://www.brandonhutchinson.com/ctime_atime_mtime.html.

homey 01-19-2006 09:27 PM

A quick google came up with the command: file -p test.txt

It may give timestamp on some distros but not on my FC box.

nitinatindore 01-19-2006 09:44 PM

Actually could you be more specific in you query why do you need some more commands when these are solving a problem.

If you are probably creating some program,I think fstat() is the system call you are looking at

gilead 01-19-2006 09:45 PM

Yep, it's the same on Slackware - using '-p' will attempt to preserve the access time, but none of the 'file' program's options display the atime, ctime or mtime.

chrism01 01-19-2006 11:38 PM

Also, the find cmd has atime/mtime/ctime options. We'd be able to help a lot more if you could give us some details as to what exactly you are trying to do.

operand 01-20-2006 03:32 AM

Thanks all you guys.
What I want is to retain only the timestamp while filter out all the others. So, a clear method to present the timestamp of a file is necessary to deal with the output of the above commands. But these outputs is too complex for me to cope with. That's it.
Thanks for your attention and look forward to your reply.

gilead 01-20-2006 04:14 AM

I hope this is what you're looking for...

If you use stat to display the info about a file and it produces the following:

Code:

$ stat 405938.png
  File: `405938.png'
  Size: 3642            Blocks: 8          IO Block: 131072 regular file
Device: 306h/774d      Inode: 1604        Links: 1
Access: (0640/-rw-r-----)  Uid: ( 1000/  steve)  Gid: (  102/  steve)
Access: 2006-01-20 00:44:33.000000000 +1000
Modify: 2006-01-05 02:23:58.000000000 +1000
Change: 2006-01-16 20:26:01.000000000 +1000

Then to get the access time:

Code:

$ stat 405938.png | grep 'Access: [[:digit:]]' | cut -d' ' -f2,3,4
2006-01-20 00:44:33.000000000 +1000

To get the modify time:

Code:

$ stat 405938.png | grep 'Modify: ' | cut -d' ' -f2,3,4
2006-01-05 02:23:58.000000000 +1000

To get the change time:

Code:

$ stat 405938.png | grep 'Change: ' | cut -d' ' -f2,3,4
2006-01-16 20:26:01.000000000 +1000



All times are GMT -5. The time now is 01:48 AM.