ExifTool Forum

ExifTool => Newbies => Topic started by: RRRichard on June 24, 2024, 07:11:30 PM

Title: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: RRRichard on June 24, 2024, 07:11:30 PM
I'm trying to use ExifTool in Linux Mint after using it successfully in Windows 10. I'm having some trouble getting multiple ExifTool commands to run in a bash script. I have 3 ExifTool commands in the script file and each command will run successfully on it's own in a terminal window. But when I put those same commands in a bash script, the commands will not run.

Here is my bash script file (dates.sh):

#!/usr/bin/bash
exiftool -r -m -overwrite_original '-alldates<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
exiftool -r -m -overwrite_original '-FileModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
exiftool -r -m -overwrite_original '-ModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .

Here is the output in terminal:

richard@Spectre:~/Downloads/Photos$ exiftool -r -m -overwrite_original '-alldates<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
    2 directories scanned
    3 image files updated
richard@Spectre:~/Downloads/Photos$ exiftool -r -m -overwrite_original '-FileModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
    2 directories scanned
    3 image files updated
richard@Spectre:~/Downloads/Photos$ exiftool -r -m -overwrite_original '-ModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
    2 directories scanned
    3 image files updated
richard@Spectre:~/Downloads/Photos$ chmod +x dates.sh
richard@Spectre:~/Downloads/Photos$ which bash
/usr/bin/bash
richard@Spectre:~/Downloads/Photos$ ./dates.sh
bash: ./dates.sh: /usr/bin/bash^M: bad interpreter: No such file or directory
richard@Spectre:~/Downloads/Photos$ bash dates.sh
Warning: Error opening file - .
Error: File not found - .
    0 image files updated
    1 files weren't updated due to errors
Warning: Error opening file - .
Error: File not found - .
    0 image files updated
    1 files weren't updated due to errors
Warning: Error opening file - .
Error: File not found - .
    0 image files updated
    1 files weren't updated due to errors
richard@Spectre:~/Downloads/Photos$

The 3 standalone ExifTool commands will run fine. But the same commands in the bash file don't run. The bash file is in the same folder as the terminal window is open in. The folder that contains the jpg files is also in the same folder. I suspect I'm doing something wrong with bash but I'm at a loss as to what it might be (I am new to Linux.)

Can anyone steer me to success?

(sheesh, newbies...  ;D )
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: StarGeek on June 24, 2024, 07:59:28 PM
Quote from: RRRichard on June 24, 2024, 07:11:30 PMbash: ./dates.sh: /usr/bin/bash^M: bad interpreter: No such file or directory

The answer is right here. Instead of trying to run bash, it's trying to run a program called bash^M .

^M == Control+M, which is a Carriage Return. Windows ends each line in a text file with Carriage Return/Line Feed, but Linux uses just the Line Feed.

Remove the CRs from the text file and see if it works then.

Edit: This StackOverflow answer (https://stackoverflow.com/a/29747593/3525475) shows how you can use sed to fix the file.
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: Phil Harvey on June 24, 2024, 09:37:21 PM
Also, you should combine the three commands into a single command:

exiftool -r -m -overwrite_original '-alldates<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' '-FileModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' '-ModifyDate<${file:directory;s/.*(\d{4})-(\d\d)-(\d\d).*/$1:$2:$3/} 12:00:00' .
- Phil
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: RRRichard on June 25, 2024, 01:17:45 AM
StarGeek,

Thank you for that 'windows transition' lesson! That "^M" did generate a little discomfort but I just didn't know what I was looking at. I re-created the file in a Linux text editor and all ran as expected. I had already passed the "change double quotes to single quotes" lesson and maybe I was feeling overconfident. I'm sure there will be more lessons to follow...

Phil,

Thank you for your suggestion to combine into one command. Based on the script output in terminal, I suspect the single command will be faster and more efficient.

One other item I'm sure you can clarify. In Windows, I also modified the "FileCreateDate" tag with ExifTool but I could not do this in Linux (Mint). I believe this is a "file system" tag. Apparently this tag may not exist in Mint. Can ExifTool modify the "Birth Date" of a file in Linux and, if so, do you know what tag ExifTool would use to do this?

This forum eliminates hours of frustration and stress for new users - THANK YOU to all that support it!
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: StarGeek on June 25, 2024, 10:34:00 AM
Quote from: RRRichard on June 25, 2024, 01:17:45 AMThank you for that 'windows transition' lesson! That "^M" did generate a little discomfort but I just didn't know what I was looking at.

Yep, that's a lesson I had to learn many years ago, when I had to transition from my Amiga (also LF only) to Windows. Welcome to the Ten Thousand (https://xkcd.com/1053/).

QuoteOne other item I'm sure you can clarify. In Windows, I also modified the "FileCreateDate" tag with ExifTool but I could not do this in Linux (Mint). I believe this is a "file system" tag. Apparently this tag may not exist in Mint. Can ExifTool modify the "Birth Date" of a file in Linux and, if so, do you know what tag ExifTool would use to do this?

Exiftool can't edit the birth date of a Linux file if it exists.  According to How to Find Out When a File Was Created in Linux (https://kodekloud.com/blog/file-creation-time-linux/)
QuoteThe addition of the file creation time (birth time) is relatively recent and is not universally supported across all filesystems
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: Phil Harvey on June 25, 2024, 10:36:58 AM
StarGeek beat me but here is my post anyway...

Use the -G1 option when extracting to see where the tag comes from.  System tags come from the file system.

Linux supports various different filesystems.  Traditionally the file creation date is not stored, but it may be for some types of filesystems.  However, ExifTool doesn't support this.

- Phil
Title: Re: ExifTool - Moving to Linux (Mint) from Windows but...
Post by: RRRichard on June 25, 2024, 11:50:30 AM
Once again, THANK YOU both for your help and clear explanations! I'm starting to feel more confident about making the "Windows to Linux" transition.  :)

Phil, thank you also for ExifTool. It has been an irreplaceable tool to support my photo collection.