So I'm trying to move images of a specific dimension to another folder. But working with a huge number of files, the same filename once and a while presents itself. And I have been using this script:
#!/bin/bash
targetDir="$HOME/Documents/pixx"
find "$targetDir" -iname '*.jpg' -o -iname '*.png' -o -iname '*.bmp' -o -iname '*.jpeg' 2>/dev/null | \
while read -r filename; do
hw="$(sips -g pixelHeight -g pixelWidth "$filename" 2>/dev/null)"
h="$(awk '/pixelHeight/{print $2}'<<<"$hw")"
w="$(awk '/pixelWidth/{print $2}'<<<"$hw")"
if [[ $h -eq 270 ]] && [[ $w -eq 360 ]]; then
mv "$filename" "$targetDir/hehe"
fi
done
I found out that mv
had a backup command mv --backup=t
but that is just for linux, so I can't use that. But it would be great to have some sort of equal function in this script above.
So how can I add a incremental number if the same filename appears?