LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2016, 08:27 AM   #1
myre75
Member
 
Registered: Nov 2013
Location: Lyon, France
Distribution: Slackware MLED 14.2 64 Bits
Posts: 30

Rep: Reputation: Disabled
Get timestamp from a file


Hi all,

I need to get timestamp from a file :

remy$ stat FAFAF3DD-D0C4-4038-9C7E-31BD6A07AA61.pdf
16777220 1076482 -rw-r--r-- 1 remy staff 0 531864 "Jan 30 15:23:36 2016" "Jan 30 15:08:21 2016" "Jan 30 15:09:55 2016" "Jan 30 15:08:21 2016" 4096 1040 0 FAFAF3DD-D0C4-4038-9C7E-31BD6A07AA61.pdf

My level in shell scripting is not quite good to get this. I mean, iIknow I can use awk, but I don't know how to get them(year, month, day)

If someone could help me, I would be so good

Thanks all
 
Old 01-30-2016, 08:31 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
M-D-Y are present in your output.
What's the problem?

Code:
stat jj
  File: `jj'
  Size: 12288     	Blocks: 24         IO Block: 4096   directory
Device: ca01h/51713d	Inode: 656870      Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-01-29 23:59:01.662706000 -0800
Modify: 2016-01-29 17:33:57.826705997 -0800
Change: 2016-01-29 17:33:57.826705997 -0800
 
Old 01-30-2016, 08:33 AM   #3
myre75
Member
 
Registered: Nov 2013
Location: Lyon, France
Distribution: Slackware MLED 14.2 64 Bits
Posts: 30

Original Poster
Rep: Reputation: Disabled
Ok so :

remy$ stat FAFAF3DD-D0C4-4038-9C7E-31BD6A07AA61.pdf | awk '{ print $16, $17, $18 }'
2016" "Jan 30

Pretty much better.

But I need to convert month in numeric. And here ... No idea :/
 
Old 01-30-2016, 08:34 AM   #4
myre75
Member
 
Registered: Nov 2013
Location: Lyon, France
Distribution: Slackware MLED 14.2 64 Bits
Posts: 30

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
M-D-Y are present in your output.
What's the problem?

Code:
stat jj
  File: `jj'
  Size: 12288     	Blocks: 24         IO Block: 4096   directory
Device: ca01h/51713d	Inode: 656870      Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-01-29 23:59:01.662706000 -0800
Modify: 2016-01-29 17:33:57.826705997 -0800
Change: 2016-01-29 17:33:57.826705997 -0800
Thank you for your answer, but I'm working on OS X with BSD tools at work

My stat command is quite different I think
 
Old 01-30-2016, 09:16 AM   #5
myre75
Member
 
Registered: Nov 2013
Location: Lyon, France
Distribution: Slackware MLED 14.2 64 Bits
Posts: 30

Original Poster
Rep: Reputation: Disabled
All is fine now, thank you

I found : stat -f "%Sm" -t "%Y%m%d" file

Thanks !
 
Old 01-30-2016, 09:33 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
You're welcome and glad it worked out on your OS X system.
 
  


Reply



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
script to timestamp files with timestamp from directory eRJe Programming 4 11-13-2013 06:52 PM
file header with timestamp groking Programming 4 02-25-2009 04:36 AM
Subversion timestamp in file darkarcon2015 Linux - Software 1 05-17-2006 07:45 PM
How to get the timestamp of a file? operand Linux - Newbie 7 01-20-2006 04:14 AM
Timestamp of file/directories Ephracis Linux - Software 1 12-16-2004 09:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:13 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
Open Source Consulting | Domain Registration