Created
April 28, 2018 09:50
-
-
Save bmarwell/0d7bf2926db565833306e7aabdc73817 to your computer and use it in GitHub Desktop.
Rename JPG image files to a standardized iso format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
NOOP=${1:-} | |
COUNTER=0 | |
if [ "$NOOP" == "-n" ]; then | |
echo "Simulation mode. -n given." | |
fi | |
for file in "$@"; do | |
newname=$(exiftool -d "%Y-%m-%dT%H-%M-%S_$(printf %04d $COUNTER)" -DateTimeOriginal -S -s -q "$file") | |
let COUNTER=COUNTER+1 | |
if [ "x$newname" == "x" ]; then | |
echo "Skipping file $file -- no date available." >&2 | |
continue | |
fi | |
echo "[$file] => [$newname].jpg" | |
if [ "$NOOP" == "-n" ]; then | |
continue | |
fi | |
mv "$file" "${newname}.jpg" & | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bash script will convert the filenames of your current directory to a standardized ISO format:
2018-04-28T11:50:00_0001.jpg
It uses its exif information.
exiftool
needs to be installed.Pass
-n
for simulation.Otherwise,
cd
to the dir you like to change and use:Executing a 2nd time might change the counter variable, because it is not determined by date. So if you like to keep your cameras ordering, don't run it a 2nd time. I always run it a 2nd time, though :)
The counter is needed, because of camera's burst modes which will do many pictures in the same second. Otherweise images would overwrite each other.
HTH
I never lost any files, but use it at your own risk.