Change dates of pictures

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
christophe14
Level 1
Level 1
Posts: 14
Joined: Wed Nov 08, 2023 7:00 am

Change dates of pictures

Post by christophe14 »

Hello,

I am in the process of migrating my pictures from iMovie (Mac) to digiKam (Linux Mint).
My problem encountered is that the files that have been copied into Linux Mint do not have anymore the correct dates.

I was able to use the tool jExifToolGUI to retrieve the EXIF Date/Time Original of a picture and to change only the Modify date.
But the other dates (Access, Change and Birth) are not changed.
I would like that all dates of a file are copied /paste from Modify date, specially the Birth date of the file.
Birth date = Modify date
Access date = Modify date
Change date = Modify date

I had fight several hours with touch command but didn't succeed.

Has anybody has done this before ?

Thanks for your help.
User avatar
trytip
Level 14
Level 14
Posts: 5370
Joined: Tue Jul 05, 2016 1:20 pm

Re: Change dates of pictures

Post by trytip »

you'll need a commander like https://sourceforge.net/projects/doublecmd/ extract and run executable doublecmd>show hidden files>file>change attributes

ps: another post the same viewtopic.php?t=270080
Image
User avatar
xenopeek
Level 25
Level 25
Posts: 29307
Joined: Wed Jul 06, 2011 3:58 am

Re: Change dates of pictures

Post by xenopeek »

That's not possible for the birth/creation date. See this earlier topic with similar question: Transfer files from mac to linux retaining metadata. As I answered there;
xenopeek wrote: Sun Jul 30, 2023 2:27 pm This isn't possible on Linux because there is no API to change the file creation time, so programs can't change or set it. There is only an API to change the last access time and last modification time of a file. On Linux the creation time — or birth time — reflects when the file first came to exist on this filesystem, not when the file was first created by its author.
Why do you need to change the filesystem time stamps? I don't know but would hope that digiKam uses the EXIF creation date tags to show when the photos were taken and to group & order them, not the filesystem birth date.
Image
t42
Level 11
Level 11
Posts: 3654
Joined: Mon Jan 20, 2014 6:48 pm

Re: Change dates of pictures

Post by t42 »

I would concentrate in what you can achieve from command line with ExifTool by Phil Harvey ( https://exiftool.org/forum/index.php?topic=9101.0) but probably it is not what you want.

If you are placing files on ext4 file system and using kernel =>5.15 and coreutils =>8.31 here is how it may look

Code: Select all

$ apt policy coreutils
coreutils:
  Installed: 8.32-4.1ubuntu1

$ uname -rv
6.5.0-1008-oem #8-Ubuntu SMP PREEMPT_DYNAMIC Fri Nov 10 13:08:33 UTC 2023

$ rm -f file && touch file && sleep 5 && touch file

$ df ~
Filesystem          1K-blocks     Used Available Use% Mounted on
/dev/mapper/p7-root  30045048 18445576  10047908  65% /

$ sudo debugfs "-R stat <$(stat -c %i file)>" /dev/mapper/p7-root | cat
         
debugfs 1.46.5 (30-Dec-2021)
Inode: 164008   Type: regular    Mode:  0664   Flags: 0x80000
Generation: 2115305098    Version: 0x00000000:00000003
User:  1000   Group:  1000   Project:     0   Size: 0
File ACL: 0
Links: 1   Blockcount: 0
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x6566410b:5bcdeb10 -- Tue Nov 28 20:35:39 2023
 atime: 0x6566410b:5bcdeb10 -- Tue Nov 28 20:35:39 2023
 mtime: 0x6566410b:5bcdeb10 -- Tue Nov 28 20:35:39 2023
 crtime: 0x65664106:5aceff84 -- Tue Nov 28 20:35:34 2023
Size of extra inode fields: 32
Inode checksum: 0x94c687d5

$ stat file
  File: file
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fc00h/64512d	Inode: 164008      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/       mf)   Gid: ( 1000/       mf)
Access: 2023-11-28 20:35:39.385055428 +0100
Modify: 2023-11-28 20:35:39.385055428 +0100
Change: 2023-11-28 20:35:39.385055428 +0100
 Birth: 2023-11-28 20:35:34.380878817 +0100
Note created for analysis 5 sec delay.
So we have Birth time otherwise indicated as crtime
-=t42=-
User avatar
AZgl1800
Level 20
Level 20
Posts: 11003
Joined: Thu Dec 31, 2015 3:20 am
Location: Oklahoma where the wind comes Sweeping down the Plains
Contact:

Re: Change dates of pictures

Post by AZgl1800 »

my sister used Win10 and previous versions.
she had 100s of photos going back 20 years.

when her PC crashed hard, and refused to boot into recovery mode, I installed LM20.3 Cinnamon.

I then used a USB Drive Dock to look at all of the Hard drives from her current PC, and the old HDDs from the other PCs...

as you said, the creation date is lost when transferring from a non-linux drive to Linux.

My solution was to note the action dates of the photos, and create Folders dated to the nearest year, month, etc....
it irked her a bit, but she was so happy to find all of her old photos, she got over the lack of creation dates.
LM21.3 Cinnamon ASUS FX705GM | Donate to Mint https://www.patreon.com/linux_mint
Image
Hoser Rob
Level 20
Level 20
Posts: 11615
Joined: Sat Dec 15, 2012 8:57 am

Re: Change dates of pictures

Post by Hoser Rob »

xenopeek wrote: Tue Nov 28, 2023 3:30 pm That's not possible for the birth/creation date. See this earlier topic with similar question: Transfer files from mac to linux retaining metadata. As I answered there;
xenopeek wrote: Sun Jul 30, 2023 2:27 pm This isn't possible on Linux because there is no API to change the file creation time, so programs can't change or set it. There is only an API to change the last access time and last modification time of a file. On Linux the creation time — or birth time — reflects when the file first came to exist on this filesystem, not when the file was first created by its author.
Why do you need to change the filesystem time stamps? I don't know but would hope that digiKam uses the EXIF creation date tags to show when the photos were taken and to group & order them, not the filesystem birth date.
True, and one of the weirdest things in Linux. The ext4 file system does actually support file creation dates AFAIK but there are no kernel APIs available so it's extremely difficult to do anything with them.
For every complex problem there is an answer that is clear, simple, and wrong - H. L. Mencken
t42
Level 11
Level 11
Posts: 3654
Joined: Mon Jan 20, 2014 6:48 pm

Re: Change dates of pictures

Post by t42 »

Besides it is impossible, there is no need to do anything with crtime - it indicates the creation of the file on current filesystem. It was an original intention, relevant xstat() patch was merged somewhere around 2010, besides other things disallowing changes to crtime, - no system calls were available to change it. Please note that crtime was even not accessible through the stat interface until coreutils version 8.32 in the summer of 2020 and it was calculated before that through inode number with stat and debugfs.
-=t42=-
mikeflan
Level 16
Level 16
Posts: 6754
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: Change dates of pictures

Post by mikeflan »

I just had this problem - probably for the first time.
If you want to change the modify date you ls -1 to list the files and then use regular expressions to create hundreds of commands similar to this one:

Code: Select all

touch -d "$(date -R -r dsc_0001.jpg) + 59 hours" dsc_0001.jpg
and then you run all the commands.
billyswong
Level 7
Level 7
Posts: 1880
Joined: Wed Aug 14, 2019 1:02 am

Re: Change dates of pictures

Post by billyswong »

Others have explained about birth date.

Access date is about when do you "access" the file. Obviously you have "accessed" the files when you copy them. So that date won't be = modify date.
KeithHelms
Level 1
Level 1
Posts: 8
Joined: Wed Nov 22, 2023 11:59 am

Re: Change dates of pictures

Post by KeithHelms »

If you're interested, I wrote a little script to set the file timestamp from the photo's exif timestamp.
If requires the libimage-exiftool-perl package to be installed.

Code: Select all

#!/bin/bash

if [ $# -ne 1 ]; then
	echo ""
	echo "USAGE: setTimestampFromExif.sh path"
	echo "The script will find all photos in the specified path or below"
	echo "and set their timestamps from the photo creation time in the EXIF data"
	echo ""
	echo "The script requires the exiftool package be installed in order to"
	echo "extract the timestamp from the EXIF data."
	echo ""
	exit
fi


ET=`which exiftool`
if [ -z "$ET" ]; then
  echo "exiftool not installed or not in path"
  exit
fi

IFS=$'\n'

for photo in `find "$1" -name '*[.jpg|.JPG|.NEF|.nef]'`
do
	timestamp=""
	timestamp=`exiftool -p '$DateTimeOriginal' "$photo"`
	if [[ ${#timestamp} -eq 19 ]]; then
		YYYY=${timestamp:0:4}
		nbrtest=`echo $YYYY | tr -d 0-9`
		if [ ! -z "$nbrtest" ]; then
			echo "year was non-numeric"
			continue
		fi
		MM=${timestamp:5:2}
		nbrtest=`echo $MM | tr -d 0-9`
		if [ ! -z "$nbrtest" ]; then
			echo "month was non-numeric"
			continue
		fi
		DD=${timestamp:8:2}
		hh=${timestamp:11:2}
		mm=${timestamp:14:2}
		ss=${timestamp:17:2}
		echo "setting \"$photo\" to timestamp $YYYY$MM$DD$hh$mm.$ss"
		touch -t "$YYYY$MM$DD$hh$mm.$ss" "$photo"
	fi
done

Post Reply

Return to “Beginner Questions”