My camera produces files like IMG_1234.JPG and MVI_1234.AVI with timestamps on those files. Unfortunately the time wasn't set properly and timestamps are off.

I would like to set the file's timestamp on disk. (not the EXIF data).

Proposed algorithm:

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

Is there an easy way to do this? maybe one could simplify the calculation using epoch time (seconds since) and whip up a shell script.

  • 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, 2010 at 20:04

6 Answers 6


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


To change the mtime, add --time=mtime

  • 1
    yes, but this is relative to your current system time, not the file's.. thanks, though..
    – index
    Mar 22, 2010 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, 2010 at 14:54
  • Brilliant, thank you. Exactly what I've been looking for. Apr 3, 2011 at 9:45
  • @rescdsk, just out of curisoity, how would this change impact a forensic analysis of the file? if you modified a file, but then set its modified date back to the previous value, would this be detectable on the inode or other filesystem metadata? would journalling impact this analysis? Aug 22, 2014 at 14:16
  • @FrankThomas, sorry, I've got no clue!
    – rescdsk
    Aug 22, 2014 at 18:07

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

Correct the file time stamps:

for i in all/*; do
  touch -r "$i" -d '-12 hour' "$i"

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.


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

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

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

  • 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, 2010 at 13:04

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.

  • A side note: while better than nothing, this syntax is a nightmare for scripting.
    – tuomassalo
    Nov 9, 2017 at 10:39
  • 1
    That's exactly what I was looking for (too lazy to RTFM :D). Thanks! Feb 11, 2018 at 8:29

Linux, using touch to change the last modified timestamp:

Create a file with timestamp of now:

el@apollo:~$ touch myfile.txt
el@apollo:~$ ll myfile.txt
-rw-rw-r-- 1 el el 0 Aug 22 09:25 myfile.txt

Change the timestamp to be 2 hours ago:

el@apollo:~$ touch -d "2 hours ago" myfile.txt
el@apollo:~$ ll myfile.txt
-rw-rw-r-- 1 el el 0 Aug 22 07:25 myfile.txt

Change the timestamp to be 200 hours ago:

el@apollo:~$ touch -d "200 hours ago" myfile.txt
el@apollo:~$ ll myfile.txt
-rw-rw-r-- 1 el el 0 Aug 14 01:25 myfile.txt

Change the timestamp to be 30 days ago:

el@apollo:~$ touch -d "30 days ago" myfile.txt
el@apollo:~$ ll myfile.txt
-rw-rw-r-- 1 el el 0 Jul 23 09:25 myfile.txt

For shenanigans, set the last modified date in the future:

el@apollo:~$ touch -d "-400000 days ago" myfile.txt
el@apollo:~$ ll myfile.txt
-rw-rw-r-- 1 el el 0 Oct 21  3012 myfile.txt

Apparently, We gonna party like it's 3012 tonight.

  • For the last "future" example, doesn't the minus (-) tell touch to go 400,000 days in the past, and yet it ends up in the future? Or wait, are you telling touch to double-negative the date, minus + ago = future...? Yar matey
    – Xen2050
    Nov 27, 2016 at 21:02

Use jhead:


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.

  • 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, 2010 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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