LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 07-12-2010, 10:08 PM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
BASH: Keep original mod date of a file and 'date' it back to same file?


I would really like to preserve a file's original modified date and pass it back to the file as the same attribute after a script has worked on it. I get a lot of JPEG files from different places on the Net which I either turn around and upload or burn to disk, and having the "original" date of either download or last mod in a graphics app would be for me, in the long run, a lot more helpful when deciding, for instance, which files to "recycle" or pass on backing up more than once.

I've tried doing this on my own every now and then. Where I run into problems is that it appears "stat" and "date" use different formats for date information, and I can't seem to puzzle out how to "translate" one to the other satisfactorily for the latter command.

Just to give an example:
stat foo.jpg |grep Modify gives me
Modify: 2010-07-12 06:28:56.890625000 -0400

Passing that string as-is to date foo.jpg, I get the error
date: unknown option -- 0 and the usual semi-courteous suggestion to Try 'date --help' for more information.

Somehow my TexInfo database got screwed up somewhere along the line and
info date
gives me the short article on date input formats, not the full documentation for the command. So any help in this regard would be much appreciated.

BZT
 
Old 07-12-2010, 10:11 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644
Try 'touch -m -d <date_string> <filename>'
 
Old 07-16-2010, 11:45 AM   #3
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by kbp View Post
Try 'touch -m -d <date_string> <filename>'
Works well enough. I'd call that a solution.
Forgot that 'touch' had those extra functions. I've been using it to create empty files into which to save data from other apps (so I don't have to type in a file name, just click on the empty and confirm the overwrite).
Time to re-acquaint myself with the MAN page, methinks.

BZT
 
Old 07-16-2010, 11:53 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
Well I can see this is SOLVED (please mark it as so), but in case you are interested:
Code:
date -d "$(stat foo.jpg | sed -n '/Modify/s/[^:]*: //p')"
 
Old 07-16-2010, 12:12 PM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
My
Code:
date -r foo.jpg
 
1 members found this post helpful.
  


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
[SOLVED] Use date with touch to create new file with date based name craigjl Linux - Newbie 5 03-12-2010 10:46 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 10:59 AM
[bash] Seeing if a file has been modified before/after a date w3stfa11 Programming 7 10-15-2006 07:02 PM
bash sort files by date in file name thedude2010 Programming 6 05-12-2006 12:07 PM
Set name of tar file as date using bash otisthegbs Linux - Software 5 12-18-2003 04:34 PM


All times are GMT -5. The time now is 10:49 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration