0

I recovered images from an android LOST.DIR folder.

The data recovered successfully, now I'd like to set the modified timestamp of the file to be equal to the created on value of the binary data.

I'm using Ubuntu 19.10

enter image description here

enter image description here

In this case, I'd like both modified and created on to equal 2019:06:03, the format doesn't matter.

The solution should support looping over all files in the folder.

  • AFAIK not tools exist for that. Also see this: https://unix.stackexchange.com/questions/591384/copying-or-restoring-crtime-for-files-directories-on-ext4fs-filesystem – Artem S. Tashkinov Feb 13 '21 at 14:47
  • 1
    @Artem S. Tashkinov: I understand the OP want to set the file system modified timestand to be equal to the EXIF creation time. The link you posted is about setting the creation time in the file system. – phunsoft Feb 13 '21 at 15:00
  • The file modified timestamp is copied and respected by most file utilities under the Sun and created on time is a whole different affair which is what the OP is seemingly looking for. – Artem S. Tashkinov Feb 13 '21 at 15:17
  • The recovery process the OP ran created new files with create and modified timestamps equal to the revocery time, right? I understand the OP would like the files system modified timestamp the reclect the creation time of the original image file (which is an EXIF tag). – phunsoft Feb 13 '21 at 15:51
  • Actually now I suspect that the recovery didn't work. Because the files doesn't have the file type suffix. But I am able to see the file type in the properties popup and to open the file in image viewer. If I add the suffix manually, I can even open it on my mobile. I tried using photorec. – noam steiner Feb 13 '21 at 16:05
  • You can open the files recovered in an image viewer and it looks like the images you expect? So the recovery did succeed, I'd say. The suffix in the file name is just part of the filename, and is interpreted by some programs. It has no influence on the content of the files. You might name a pure text file "image.jpg", but that doesn't make an image out of it. Rename the files and add the suffix (jpg, tif, or whatever applies). – phunsoft Feb 13 '21 at 16:10
  • Ok, than the recovery did work. – noam steiner Feb 13 '21 at 16:18

1 Answers1

2

You need an EXIF tool to retrieve the image creation timestamp, then use touch to set the filesystem timestamp accordingly.

I just tried this shell script (e.g. ex.sh) under ArchLinux where I installed perl-image-exiftool

#! /bin/bash

for fn; do ls -l "$fn" touch -m -t "$(exiftool -createdate -d '%Y%m%d%H%M.%S' -s3 "$fn")" "$fn" ls -l "$fn" echo "------------------" done

You can omit the echo and ls... lines; they're just there to display before and after timestamps of the files.

./ex.sh *.jpg

or

./ex.sh 01.jpg 02.jpg
Freddy
  • 25,565
phunsoft
  • 178
  • 8