Organizing photos by geolocation from the command line

Fri 21 June 2024

Want to organize your photos by gps/geolocation, but don't feel like dealing with a slow GUI app?

That's ok, you can do it from the command line!

precision=2
for file in *.jp*g
do
    coord=$(exiftool -c "%.${precision}f" "$file" |grep GPS.Position |sed 's/^[^:]*:[[:space:]]*//')
    dir="gps/$coord"
    if mkdir -p "$dir"; then
        mv "$file" "$dir/" || echo "ERROR moving $file"
    else
        echo "ERROR creating $dir"
    fi 
done

Note that the $precision variable defines how many decimals of precision to use when sorting the photos. I found that 2 is usually good to give an approximate location, but if you have several photos right next to each other, you may wish to run it again on the conjoined set with a higher precision. The default for exiftool is 6.

Category: QuickPost Tagged: Computing Informal post Linux Non-religious post Productivity QuickPost Unix Tips


Page 1 of 1