LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2006, 09:53 PM   #1
operand
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Rep: Reputation: 0
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.
 
Old 01-19-2006, 10:10 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
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.
 
Old 01-19-2006, 10:27 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
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.
 
Old 01-19-2006, 10:44 PM   #4
nitinatindore
Member
 
Registered: Dec 2004
Location: India
Distribution: Mandrake, Mandriva, PclinuxOS
Posts: 114

Rep: Reputation: 15
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
 
Old 01-19-2006, 10:45 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
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.
 
Old 01-20-2006, 12:38 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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.
 
Old 01-20-2006, 04:32 AM   #7
operand
LQ Newbie
 
Registered: Sep 2005
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 01-20-2006, 05:14 AM   #8
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
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

Last edited by gilead; 01-20-2006 at 05:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Timestamp Help jch02140 Linux - Newbie 7 03-17-2006 03:33 AM
Samba File Modified Timestamp Problem nkeeter Linux - General 1 12-05-2005 11:30 AM
Insert date and timestamp Into File name petenyce Linux - Newbie 9 10-13-2005 01:16 PM
Timestamp of file/directories Ephracis Linux - Software 1 12-16-2004 10:21 AM
add timestamp to name of file how? supafly Linux - General 3 11-14-2001 12:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration