Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My Canon camera produces files like IMG_1234.JPG and MVI_1234.AVI. It also timestamps those files. Unfortunately during a trip to another timezone several cameras were used, one of which did not have the correct time zone set -> meta data mess.. Now I would like to correct this (not EXIF, the file's "modify" timestamp on disk).

Proposed algorithm:

1 read file's modify date
2 add delta, i.e. hhmmss (preferred: change timezone)
3 write new timestamp

Unless someone knows a tool or a combination of tools that do the trick directly, maybe one could simplify the calculation using epoch time (seconds since ..) and whip up a shell script.

Any help appreciated!

share|improve this question
    
The keyword is mtime. However, I haven't found a solution yet, as I need a change relative to the file's mtime, not current time as described in unixtutorial.org/2008/11/… –  index Mar 22 '10 at 20:04
add comment

5 Answers 5

up vote 9 down vote accepted

touch can do this:

 $ ls -l something
-rw-rw-r-- 1 tgs tgs 0 2010-03-22 16:03 something
 $ touch -r something -d '-1 day' something 
 $ ls -l something 
-rw-rw-r-- 1 tgs tgs 0 2010-03-21 16:03 something

http://linux.about.com/library/cmd/blcmdl_touch.htm

To change the mtime, add --time=mtime

share|improve this answer
    
yes, but this is relative to your current system time, not the file's.. thanks, though.. –  index Mar 22 '10 at 20:49
1  
When I first answered, yes, but I edited the answer. When you use the -r file option, it becomes relative to that file. So if you have the time be relative to the same file you're manipulating, you get what you want. –  rescdsk Mar 23 '10 at 14:54
    
Brilliant, thank you. Exactly what I've been looking for. –  Artem Russakovskii Apr 3 '11 at 9:45
add comment

Combining the above, if AM/PM was wrong...

Correct the file time stamps:

    #!/bin/sh
    for i in all/*; do
      touch -r "$i" -d '-12 hour' "$i"
    done

Then update the EXIF info in the jpg files to the corrected time stamp:

    $ jhead -dsft *.jpg

Don't forget to fix the time setting in your camera :)

share|improve this answer
add comment

iterates over all files in the subdirectory all: use stat to get the files epoch / unix time in seconds, let touch parse the sum as new date for mtime and write to file

#!/bin/sh
for i in all/*; do
  touch -m -d "$(stat -c %y "$i") + 3600 sec" "$i"
done

for a pythonian approach see http://stackoverflow.com/questions/1158076/implement-touch-using-python

share|improve this answer
    
just to clarify, this means that corutil's date parser does not only accept relative, semantic times but actually can calculate! Just pointing it out as I did not find that information in the documentation (gnu.org/software/coreutils/manual/…) [It's actually there: "Relative items adjust a date (or the current date if none) forward or backward. The effects of relative items accumulate."] –  index Mar 23 '10 at 13:04
add comment

Use jhead:

http://www.sentex.net/~mwandel/jhead/usage.html

Adjust time stored in the Exif header by h:mm backwards or forwards. Useful when having taken pictures with the wrong time set on the camera, such as after travelling across time zones, or when daylight savings time has changed.

share|improve this answer
    
Thanks for the tip, this is similar to exif and exifTool and like digiKam's "Adjust Date and Time" feature -- but I would like to modify the file's system date. Another problem is that my smart OS seems to convert times to local time on the fly and DST has kicked in in one time zone :-) –  index Mar 22 '10 at 19:42
add comment

I am doing the same thing in OS X, and the syntax of touch varies here a bit.

I am using:

touch -r "filename" -A '013007' "filename"

This will adjust +1hour 30min 7sec relative to the original modified time. '-013007' for turning the time back.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.