Modifying photo's date stored inside the photo file from files name?












-1















I am using Google's PhotScan app to scan all my old photos that are taken before the digital cameras age, and I am saving these photos using the date of the photo (example: 19821011_trip.jpg, yyyymmdd_trip.jpg).



But this method saves the current date of taking the photo using the app in the photo's properties, so what I was trying to write is a script that will take the date information from the photo's filename and correct the date that is stored in the photo's file properties.



Looking forward to get your help.










share|improve this question

























  • Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

    – George Udosen
    Jan 26 at 8:11
















-1















I am using Google's PhotScan app to scan all my old photos that are taken before the digital cameras age, and I am saving these photos using the date of the photo (example: 19821011_trip.jpg, yyyymmdd_trip.jpg).



But this method saves the current date of taking the photo using the app in the photo's properties, so what I was trying to write is a script that will take the date information from the photo's filename and correct the date that is stored in the photo's file properties.



Looking forward to get your help.










share|improve this question

























  • Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

    – George Udosen
    Jan 26 at 8:11














-1












-1








-1








I am using Google's PhotScan app to scan all my old photos that are taken before the digital cameras age, and I am saving these photos using the date of the photo (example: 19821011_trip.jpg, yyyymmdd_trip.jpg).



But this method saves the current date of taking the photo using the app in the photo's properties, so what I was trying to write is a script that will take the date information from the photo's filename and correct the date that is stored in the photo's file properties.



Looking forward to get your help.










share|improve this question
















I am using Google's PhotScan app to scan all my old photos that are taken before the digital cameras age, and I am saving these photos using the date of the photo (example: 19821011_trip.jpg, yyyymmdd_trip.jpg).



But this method saves the current date of taking the photo using the app in the photo's properties, so what I was trying to write is a script that will take the date information from the photo's filename and correct the date that is stored in the photo's file properties.



Looking forward to get your help.







scripts media metadata photo exif






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 26 at 17:17









PerlDuck

6,78211535




6,78211535










asked Jan 26 at 8:06









Dark Edge 2008Dark Edge 2008

136




136













  • Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

    – George Udosen
    Jan 26 at 8:11



















  • Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

    – George Udosen
    Jan 26 at 8:11

















Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

– George Udosen
Jan 26 at 8:11





Please show an example of the original name and the new name so we can determine if the new files can be identified from the old name so renaming can be possible!

– George Udosen
Jan 26 at 8:11










2 Answers
2






active

oldest

votes


















2















exiftool to the rescue



I assume you want to change the EXIF data of your scanned images according to the timestamp from the image's filename (not from the time the file was created like e.g. ls -l shows).



Fortunately, there is a handy tool for this called exiftool. If it is not yet installed, run



sudo apt install libimage-exiftool-perl


first. exiftool is in the standard repositories. It can show and manipulate both filenames and EXIF data. For example, it is possible to move files around according to the EXIF attribute CreateDate and move files to subdirectories like



2018
Jan
img0001.jpg
img0002.jpg
Feb
img0003.jpg
img0004.jpg


and so on. But that's another story and you want it just the other way round.



Let's take your 19821011_trip.jpg as an example and set all three attributes DateTimeOriginal, CreateDate, and ModifyDate to Oct 11, 1982. exiftool has a parameter to parse the filename for something that looks like a date and timestamp and then set all these dates at once to that value. Unfortunately the filename must contain a timestamp (HHMMSS) for this to work, like so:



exiftool "-alldates<filename" 19821011_130000_trip.jpg


This would set the three date attributes mentioned above to Oct 11, 1982, 01:00:00 PM. Since your filename does not contain such an HHMMSS part, we must change the parameter a bit:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg 


This will pick the first 8 characters from the filename, append 13:00:00 and finally parse that string (19821011 13:00:00) to build a proper date for all three attributes. exiftool is pretty good at parsing timestamps, but it needs at least an HHMM part after the date.



You can also run exiftool on a whole directory:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' .


It will then process all images it finds. No worries, it makes backups of all modified files.



Summary:



me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
(no output)

me@ubuntu:~> exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg
1 image files updated

me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
Date/Time Original : 1982:10:11 13:00:00
Create Date : 1982:10:11 13:00:00
Modify Date : 1982:10:11 13:00:00





share|improve this answer



















  • 1





    The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

    – StarGeek
    Jan 26 at 16:55











  • @StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

    – PerlDuck
    Jan 26 at 17:11













  • Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

    – StarGeek
    Jan 26 at 17:24











  • It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

    – PerlDuck
    Jan 26 at 17:33








  • 1





    The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

    – StarGeek
    Jan 26 at 18:46



















1














You could do that with touch and a loop like



for i in *.jpg; do
touch -d"${i%_trip.jpg}" "$i"
done


but that’s not very exact, as your file names only contain the date without any time information, the file’s time will thus be set to 00:00:00.000000000. Stay with me for a better way.



Every regular photo has an Exif header which contains the correct time stamp of when the photo was taken, provided the date and time settings of the camera were correct. I always prefer using this, it’s failproof and easy with jhead from the package jhead, see man jhead for details. Some useful options are:



-ft    Sets the file's system time stamp to what is stored in the Exif header.    
-n[format_string]
This option causes files to be renamed and/ or mmoved using the date information from the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal
does not contain a valid value, the file date is used. If the new name contains a '/', this will be interpreted as a new path, and the file will be moved accordingly.


A command to rename all jpg files in the current directory according to their Exif header time stamp and changing the file's system time stamp could be:



jhead -ft -n'%Y%m%d_trip' *.jpg


jhead is wise enough not to overwrite your files if the filename already exists:




If the target name already exists, the name will be appended with "a",
"b", "c", etc, unless the name ends with a letter, in which case it
will be appended with "0", "1", "2", etc.




If your files don’t have an Exif header the following options may be of help:



-mkexif
Creates minimal exif header. Exif header contains date/time, and empty thumbnail fields only. Date/time set to file time by default. Use with -rgt option if you want the exif header to
contain a thumbnail. Note that exif header creation is very limited at this time, and no other fields can be added to the exif header this way.
-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.





share|improve this answer





















  • 1





    To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

    – PerlDuck
    Jan 26 at 10:28











  • @PerlDuck Thanks, I didn’t realize that, see my update.

    – dessert
    Jan 26 at 10:38











  • @dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

    – Dark Edge 2008
    Jan 27 at 8:05













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1113001%2fmodifying-photos-date-stored-inside-the-photo-file-from-files-name%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2















exiftool to the rescue



I assume you want to change the EXIF data of your scanned images according to the timestamp from the image's filename (not from the time the file was created like e.g. ls -l shows).



Fortunately, there is a handy tool for this called exiftool. If it is not yet installed, run



sudo apt install libimage-exiftool-perl


first. exiftool is in the standard repositories. It can show and manipulate both filenames and EXIF data. For example, it is possible to move files around according to the EXIF attribute CreateDate and move files to subdirectories like



2018
Jan
img0001.jpg
img0002.jpg
Feb
img0003.jpg
img0004.jpg


and so on. But that's another story and you want it just the other way round.



Let's take your 19821011_trip.jpg as an example and set all three attributes DateTimeOriginal, CreateDate, and ModifyDate to Oct 11, 1982. exiftool has a parameter to parse the filename for something that looks like a date and timestamp and then set all these dates at once to that value. Unfortunately the filename must contain a timestamp (HHMMSS) for this to work, like so:



exiftool "-alldates<filename" 19821011_130000_trip.jpg


This would set the three date attributes mentioned above to Oct 11, 1982, 01:00:00 PM. Since your filename does not contain such an HHMMSS part, we must change the parameter a bit:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg 


This will pick the first 8 characters from the filename, append 13:00:00 and finally parse that string (19821011 13:00:00) to build a proper date for all three attributes. exiftool is pretty good at parsing timestamps, but it needs at least an HHMM part after the date.



You can also run exiftool on a whole directory:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' .


It will then process all images it finds. No worries, it makes backups of all modified files.



Summary:



me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
(no output)

me@ubuntu:~> exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg
1 image files updated

me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
Date/Time Original : 1982:10:11 13:00:00
Create Date : 1982:10:11 13:00:00
Modify Date : 1982:10:11 13:00:00





share|improve this answer



















  • 1





    The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

    – StarGeek
    Jan 26 at 16:55











  • @StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

    – PerlDuck
    Jan 26 at 17:11













  • Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

    – StarGeek
    Jan 26 at 17:24











  • It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

    – PerlDuck
    Jan 26 at 17:33








  • 1





    The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

    – StarGeek
    Jan 26 at 18:46
















2















exiftool to the rescue



I assume you want to change the EXIF data of your scanned images according to the timestamp from the image's filename (not from the time the file was created like e.g. ls -l shows).



Fortunately, there is a handy tool for this called exiftool. If it is not yet installed, run



sudo apt install libimage-exiftool-perl


first. exiftool is in the standard repositories. It can show and manipulate both filenames and EXIF data. For example, it is possible to move files around according to the EXIF attribute CreateDate and move files to subdirectories like



2018
Jan
img0001.jpg
img0002.jpg
Feb
img0003.jpg
img0004.jpg


and so on. But that's another story and you want it just the other way round.



Let's take your 19821011_trip.jpg as an example and set all three attributes DateTimeOriginal, CreateDate, and ModifyDate to Oct 11, 1982. exiftool has a parameter to parse the filename for something that looks like a date and timestamp and then set all these dates at once to that value. Unfortunately the filename must contain a timestamp (HHMMSS) for this to work, like so:



exiftool "-alldates<filename" 19821011_130000_trip.jpg


This would set the three date attributes mentioned above to Oct 11, 1982, 01:00:00 PM. Since your filename does not contain such an HHMMSS part, we must change the parameter a bit:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg 


This will pick the first 8 characters from the filename, append 13:00:00 and finally parse that string (19821011 13:00:00) to build a proper date for all three attributes. exiftool is pretty good at parsing timestamps, but it needs at least an HHMM part after the date.



You can also run exiftool on a whole directory:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' .


It will then process all images it finds. No worries, it makes backups of all modified files.



Summary:



me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
(no output)

me@ubuntu:~> exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg
1 image files updated

me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
Date/Time Original : 1982:10:11 13:00:00
Create Date : 1982:10:11 13:00:00
Modify Date : 1982:10:11 13:00:00





share|improve this answer



















  • 1





    The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

    – StarGeek
    Jan 26 at 16:55











  • @StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

    – PerlDuck
    Jan 26 at 17:11













  • Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

    – StarGeek
    Jan 26 at 17:24











  • It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

    – PerlDuck
    Jan 26 at 17:33








  • 1





    The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

    – StarGeek
    Jan 26 at 18:46














2












2








2








exiftool to the rescue



I assume you want to change the EXIF data of your scanned images according to the timestamp from the image's filename (not from the time the file was created like e.g. ls -l shows).



Fortunately, there is a handy tool for this called exiftool. If it is not yet installed, run



sudo apt install libimage-exiftool-perl


first. exiftool is in the standard repositories. It can show and manipulate both filenames and EXIF data. For example, it is possible to move files around according to the EXIF attribute CreateDate and move files to subdirectories like



2018
Jan
img0001.jpg
img0002.jpg
Feb
img0003.jpg
img0004.jpg


and so on. But that's another story and you want it just the other way round.



Let's take your 19821011_trip.jpg as an example and set all three attributes DateTimeOriginal, CreateDate, and ModifyDate to Oct 11, 1982. exiftool has a parameter to parse the filename for something that looks like a date and timestamp and then set all these dates at once to that value. Unfortunately the filename must contain a timestamp (HHMMSS) for this to work, like so:



exiftool "-alldates<filename" 19821011_130000_trip.jpg


This would set the three date attributes mentioned above to Oct 11, 1982, 01:00:00 PM. Since your filename does not contain such an HHMMSS part, we must change the parameter a bit:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg 


This will pick the first 8 characters from the filename, append 13:00:00 and finally parse that string (19821011 13:00:00) to build a proper date for all three attributes. exiftool is pretty good at parsing timestamps, but it needs at least an HHMM part after the date.



You can also run exiftool on a whole directory:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' .


It will then process all images it finds. No worries, it makes backups of all modified files.



Summary:



me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
(no output)

me@ubuntu:~> exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg
1 image files updated

me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
Date/Time Original : 1982:10:11 13:00:00
Create Date : 1982:10:11 13:00:00
Modify Date : 1982:10:11 13:00:00





share|improve this answer














exiftool to the rescue



I assume you want to change the EXIF data of your scanned images according to the timestamp from the image's filename (not from the time the file was created like e.g. ls -l shows).



Fortunately, there is a handy tool for this called exiftool. If it is not yet installed, run



sudo apt install libimage-exiftool-perl


first. exiftool is in the standard repositories. It can show and manipulate both filenames and EXIF data. For example, it is possible to move files around according to the EXIF attribute CreateDate and move files to subdirectories like



2018
Jan
img0001.jpg
img0002.jpg
Feb
img0003.jpg
img0004.jpg


and so on. But that's another story and you want it just the other way round.



Let's take your 19821011_trip.jpg as an example and set all three attributes DateTimeOriginal, CreateDate, and ModifyDate to Oct 11, 1982. exiftool has a parameter to parse the filename for something that looks like a date and timestamp and then set all these dates at once to that value. Unfortunately the filename must contain a timestamp (HHMMSS) for this to work, like so:



exiftool "-alldates<filename" 19821011_130000_trip.jpg


This would set the three date attributes mentioned above to Oct 11, 1982, 01:00:00 PM. Since your filename does not contain such an HHMMSS part, we must change the parameter a bit:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg 


This will pick the first 8 characters from the filename, append 13:00:00 and finally parse that string (19821011 13:00:00) to build a proper date for all three attributes. exiftool is pretty good at parsing timestamps, but it needs at least an HHMM part after the date.



You can also run exiftool on a whole directory:



exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' .


It will then process all images it finds. No worries, it makes backups of all modified files.



Summary:



me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
(no output)

me@ubuntu:~> exiftool '-alldates<${filename;$_=substr($_,0,8)} 13:00:00' 19821011_trip.jpg
1 image files updated

me@ubuntu:~> exiftool -alldates 19821011_trip.jpg
Date/Time Original : 1982:10:11 13:00:00
Create Date : 1982:10:11 13:00:00
Modify Date : 1982:10:11 13:00:00






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 26 at 16:12









PerlDuckPerlDuck

6,78211535




6,78211535








  • 1





    The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

    – StarGeek
    Jan 26 at 16:55











  • @StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

    – PerlDuck
    Jan 26 at 17:11













  • Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

    – StarGeek
    Jan 26 at 17:24











  • It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

    – PerlDuck
    Jan 26 at 17:33








  • 1





    The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

    – StarGeek
    Jan 26 at 18:46














  • 1





    The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

    – StarGeek
    Jan 26 at 16:55











  • @StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

    – PerlDuck
    Jan 26 at 17:11













  • Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

    – StarGeek
    Jan 26 at 17:24











  • It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

    – PerlDuck
    Jan 26 at 17:33








  • 1





    The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

    – StarGeek
    Jan 26 at 18:46








1




1





The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

– StarGeek
Jan 26 at 16:55





The use of the substr to pull the numbers is unnecessary. See Exiftool FAQ 5, paragraph 3. All you need to do in this case is exiftool '-alldates<$Filename 13:00:00' DIR If there are other numbers that aren't part of the date/time, then you would have to parse in some way.

– StarGeek
Jan 26 at 16:55













@StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

– PerlDuck
Jan 26 at 17:11







@StarGeek That is even better and it works for the filename 19821011_trip.jpg. I'll add that information to the answer as soon as I have some spare time. But feel invited to update my post. However, I didn't manage to fetch that information from the FAQ. :-( Maybe, because I don't know what XMP is.

– PerlDuck
Jan 26 at 17:11















Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

– StarGeek
Jan 26 at 17:24





Sorry, I wasn't counting the examples as paragraphs. Skip to the part that starts "Having said this, ExifTool is very flexible about the actual format of input date/time values when writing" tl;dr is that exiftool will ignore the non-numeric characters and treat the numbers as YYYYMMDD HHmmSS.

– StarGeek
Jan 26 at 17:24













It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

– PerlDuck
Jan 26 at 17:33







It's complicated. I tried exiftool '-alldates<filename' 19821011_trip.jpg first and that complained about invalid date/time format. exiftool '-alldates<filename' 19821011_130000_trip.jpg worked but that's not the actual filename, and I added that substr stuff. But your suggestion exiftool '-alldates<$Filename 13:00' 19821011_trip.jpg works and is easier to read and write. Thank you again.

– PerlDuck
Jan 26 at 17:33






1




1





The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

– StarGeek
Jan 26 at 18:46





The substring (or regex substitution) is good to remember in case there is any additional non-time based numbers, such as a file increment e.g 19821011_trip_001.jpg, 19821011_trip_002.jpg, etc. In those cases, you do need do something extra to get only the numbers you need.

– StarGeek
Jan 26 at 18:46













1














You could do that with touch and a loop like



for i in *.jpg; do
touch -d"${i%_trip.jpg}" "$i"
done


but that’s not very exact, as your file names only contain the date without any time information, the file’s time will thus be set to 00:00:00.000000000. Stay with me for a better way.



Every regular photo has an Exif header which contains the correct time stamp of when the photo was taken, provided the date and time settings of the camera were correct. I always prefer using this, it’s failproof and easy with jhead from the package jhead, see man jhead for details. Some useful options are:



-ft    Sets the file's system time stamp to what is stored in the Exif header.    
-n[format_string]
This option causes files to be renamed and/ or mmoved using the date information from the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal
does not contain a valid value, the file date is used. If the new name contains a '/', this will be interpreted as a new path, and the file will be moved accordingly.


A command to rename all jpg files in the current directory according to their Exif header time stamp and changing the file's system time stamp could be:



jhead -ft -n'%Y%m%d_trip' *.jpg


jhead is wise enough not to overwrite your files if the filename already exists:




If the target name already exists, the name will be appended with "a",
"b", "c", etc, unless the name ends with a letter, in which case it
will be appended with "0", "1", "2", etc.




If your files don’t have an Exif header the following options may be of help:



-mkexif
Creates minimal exif header. Exif header contains date/time, and empty thumbnail fields only. Date/time set to file time by default. Use with -rgt option if you want the exif header to
contain a thumbnail. Note that exif header creation is very limited at this time, and no other fields can be added to the exif header this way.
-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.





share|improve this answer





















  • 1





    To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

    – PerlDuck
    Jan 26 at 10:28











  • @PerlDuck Thanks, I didn’t realize that, see my update.

    – dessert
    Jan 26 at 10:38











  • @dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

    – Dark Edge 2008
    Jan 27 at 8:05


















1














You could do that with touch and a loop like



for i in *.jpg; do
touch -d"${i%_trip.jpg}" "$i"
done


but that’s not very exact, as your file names only contain the date without any time information, the file’s time will thus be set to 00:00:00.000000000. Stay with me for a better way.



Every regular photo has an Exif header which contains the correct time stamp of when the photo was taken, provided the date and time settings of the camera were correct. I always prefer using this, it’s failproof and easy with jhead from the package jhead, see man jhead for details. Some useful options are:



-ft    Sets the file's system time stamp to what is stored in the Exif header.    
-n[format_string]
This option causes files to be renamed and/ or mmoved using the date information from the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal
does not contain a valid value, the file date is used. If the new name contains a '/', this will be interpreted as a new path, and the file will be moved accordingly.


A command to rename all jpg files in the current directory according to their Exif header time stamp and changing the file's system time stamp could be:



jhead -ft -n'%Y%m%d_trip' *.jpg


jhead is wise enough not to overwrite your files if the filename already exists:




If the target name already exists, the name will be appended with "a",
"b", "c", etc, unless the name ends with a letter, in which case it
will be appended with "0", "1", "2", etc.




If your files don’t have an Exif header the following options may be of help:



-mkexif
Creates minimal exif header. Exif header contains date/time, and empty thumbnail fields only. Date/time set to file time by default. Use with -rgt option if you want the exif header to
contain a thumbnail. Note that exif header creation is very limited at this time, and no other fields can be added to the exif header this way.
-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.





share|improve this answer





















  • 1





    To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

    – PerlDuck
    Jan 26 at 10:28











  • @PerlDuck Thanks, I didn’t realize that, see my update.

    – dessert
    Jan 26 at 10:38











  • @dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

    – Dark Edge 2008
    Jan 27 at 8:05
















1












1








1







You could do that with touch and a loop like



for i in *.jpg; do
touch -d"${i%_trip.jpg}" "$i"
done


but that’s not very exact, as your file names only contain the date without any time information, the file’s time will thus be set to 00:00:00.000000000. Stay with me for a better way.



Every regular photo has an Exif header which contains the correct time stamp of when the photo was taken, provided the date and time settings of the camera were correct. I always prefer using this, it’s failproof and easy with jhead from the package jhead, see man jhead for details. Some useful options are:



-ft    Sets the file's system time stamp to what is stored in the Exif header.    
-n[format_string]
This option causes files to be renamed and/ or mmoved using the date information from the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal
does not contain a valid value, the file date is used. If the new name contains a '/', this will be interpreted as a new path, and the file will be moved accordingly.


A command to rename all jpg files in the current directory according to their Exif header time stamp and changing the file's system time stamp could be:



jhead -ft -n'%Y%m%d_trip' *.jpg


jhead is wise enough not to overwrite your files if the filename already exists:




If the target name already exists, the name will be appended with "a",
"b", "c", etc, unless the name ends with a letter, in which case it
will be appended with "0", "1", "2", etc.




If your files don’t have an Exif header the following options may be of help:



-mkexif
Creates minimal exif header. Exif header contains date/time, and empty thumbnail fields only. Date/time set to file time by default. Use with -rgt option if you want the exif header to
contain a thumbnail. Note that exif header creation is very limited at this time, and no other fields can be added to the exif header this way.
-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.





share|improve this answer















You could do that with touch and a loop like



for i in *.jpg; do
touch -d"${i%_trip.jpg}" "$i"
done


but that’s not very exact, as your file names only contain the date without any time information, the file’s time will thus be set to 00:00:00.000000000. Stay with me for a better way.



Every regular photo has an Exif header which contains the correct time stamp of when the photo was taken, provided the date and time settings of the camera were correct. I always prefer using this, it’s failproof and easy with jhead from the package jhead, see man jhead for details. Some useful options are:



-ft    Sets the file's system time stamp to what is stored in the Exif header.    
-n[format_string]
This option causes files to be renamed and/ or mmoved using the date information from the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal
does not contain a valid value, the file date is used. If the new name contains a '/', this will be interpreted as a new path, and the file will be moved accordingly.


A command to rename all jpg files in the current directory according to their Exif header time stamp and changing the file's system time stamp could be:



jhead -ft -n'%Y%m%d_trip' *.jpg


jhead is wise enough not to overwrite your files if the filename already exists:




If the target name already exists, the name will be appended with "a",
"b", "c", etc, unless the name ends with a letter, in which case it
will be appended with "0", "1", "2", etc.




If your files don’t have an Exif header the following options may be of help:



-mkexif
Creates minimal exif header. Exif header contains date/time, and empty thumbnail fields only. Date/time set to file time by default. Use with -rgt option if you want the exif header to
contain a thumbnail. Note that exif header creation is very limited at this time, and no other fields can be added to the exif header this way.
-dsft Sets the Exif timestamp to the file's timestamp. Requires an Exif header to pre-exist. Use -mkexif option to create one if needed.






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 26 at 10:37

























answered Jan 26 at 8:28









dessertdessert

24.1k670104




24.1k670104








  • 1





    To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

    – PerlDuck
    Jan 26 at 10:28











  • @PerlDuck Thanks, I didn’t realize that, see my update.

    – dessert
    Jan 26 at 10:38











  • @dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

    – Dark Edge 2008
    Jan 27 at 8:05
















  • 1





    To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

    – PerlDuck
    Jan 26 at 10:28











  • @PerlDuck Thanks, I didn’t realize that, see my update.

    – dessert
    Jan 26 at 10:38











  • @dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

    – Dark Edge 2008
    Jan 27 at 8:05










1




1





To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

– PerlDuck
Jan 26 at 10:28





To my understanding the OP just wants it the other way round: set the Exif data to the timestamp from the filename. Maybe exiftool can do that.

– PerlDuck
Jan 26 at 10:28













@PerlDuck Thanks, I didn’t realize that, see my update.

– dessert
Jan 26 at 10:38





@PerlDuck Thanks, I didn’t realize that, see my update.

– dessert
Jan 26 at 10:38













@dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

– Dark Edge 2008
Jan 27 at 8:05







@dessert thanks for your reply, I have tried: // for i in *.jpg; do touch -d"${i%_trip.jpg}" "$i" done// but point the "_trip is not constant part in all file names, sometimes _numbers sometime _letters so I was trying to modify your for loop but I did not find a way. What is constant in filename is that it always start with 8 characters that presents the date YYYYMMDD.

– Dark Edge 2008
Jan 27 at 8:05




















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1113001%2fmodifying-photos-date-stored-inside-the-photo-file-from-files-name%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Human spaceflight

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

張江高科駅