Last active
December 24, 2015 01:29
-
-
Save jhanschoo/6723841 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
for FILENAME in "$@" | |
do | |
export FILENAME | |
NEWNAME="$(exiv2 $FILENAME | grep "Image timestamp" | cut -d ' ' -f 4,5 | sed 's/\(.*\) \(.*\)/\1T\2.jpg/')" | |
# don't forget to quote | |
if [ "$NEWNAME" != "" ] # equivalent to [ -n "$NEWNAME" ] | |
then | |
mv "$FILENAME" "$NEWNAME" | |
elif [ ! -e "$FILENAME" ] # file does not exist | |
then | |
echo "$0: $FILENAME: No such file" 1>&2 | |
else | |
echo "$0: $FILENAME: No EXIF timestamp" 1>&2 | |
fi | |
done |
This file contains hidden or 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 | |
while getopts "e:" opt "$@" | |
do | |
case $opt in | |
e) | |
export EXTENSION="$OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
;; | |
esac | |
done | |
for FILENAME in "${@:$OPTIND}" | |
do | |
export FILENAME | |
# this line is changed | |
NEWNAME="$(exiv2 $FILENAME | grep "Image timestamp" | cut -d ' ' -f 4,5 | sed 's/\(.*\) \(.*\)/\1T\2'"$EXTENSION"'/')" | |
# don't forget to quote | |
if [ "$NEWNAME" != "" ] # equivalent to [ -n "$NEWNAME" ] | |
then | |
mv "$FILENAME" "$NEWNAME" | |
elif [ ! -e "$FILENAME" ] # file does not exist | |
then | |
echo "$0: $FILENAME: No such file" >&2 | |
else | |
echo "$0: $FILENAME: No EXIF timestamp" >&2 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment