#!/bin/sh [ -z "$1" ] && printf "Usage: rename_image.sh \n" && exit 2; chop() { local S="$1" # no. of characters to chop local L="$2" # full text local COLS=$(tput cols) local C=$(($COLS-$S)) printf '%s' "$L" | awk -vC="$C" \ '{ line=substr($0,length($0)-C,C+1) } { if (length($0) > C) print "..."line; else print $0 }' } find "$1" -type f -iname "*.cr2" -o -iname "*.crw" -o -iname "*.nef" \ -o -iname "*.dng" \ | while read L; do F="${L##*/}" if printf '%s' "$F" | grep -qE "^[0-9]{8}_[0-9]{6}_.*"; then printf '%s\n' "↷ Skipping: $(chop "16" "$L")" else if exiv2 -r'%Y%m%d_%H%M%S_(:basename:)' rename "$L" \ > /dev/null 2>&1; then printf '%s\n' "✓ Renaming: $(chop "16" "$L")" else printf '%s\n' "↯ Failed: $(chop "14" "$L")" fi fi done