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!

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

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