Organize your pictures by EXIF tags with bash

Just a simple script to order your thousands of pictures by putting them in subdirectories on the basis of EXIF shot date:

#!/bin/bash
# BashButler 1.0 - 11/2007 by Eugenio Rustico
# Bash script to organize your pictures in folders by date
#
# GPL v3 license http://www.gnu.org/licenses/gpl-3.0.html

ls -1 *.jpg | while read fn
do
export dt=`exiv2 "$fn" | grep timestamp | awk '{ print $4 }' | tr ":" "-"`
if test ! -e ./$dt
then
mkdir $dt
fi
mv "$fn" ./$dt
echo File "$fn" moved in "$dt"
done

echo Good job!

I wrote it to setup 4.900 pictures which were all in the same directory, and it was really fast and useful. My unstoppable sense of humor conceived this amazing script name: Bash Butler. I'm very sorry for this. =)

Notes:
  • Of course you need exiv2 package on your system, but you can use other cli exif tools by modifying only one row;
  • With very little changes, you can modify the script to organize your pictures by different EXIF tags (e.g. different folders for different digital cameras);
  • Filenames with spaces are treated correctly;
  • By default mv does'nt overwrite destination files: so all remaining files in current directory are copies, and can be deleted.
GPL license v.3, of course.

7 comments:

Anonymous said...

Thanks, just what I was looking for... so simple.

Anonymous said...

Really many thanks. This is exactly what I was looking for.

Unknown said...

Here is an enhanced version: organize

Kaan said...

#!/bin/bash
# PictureRenamer 1.0 - 08/2009 by Kaan Atasever
# This script renames your pictures with date and time
#
# GPL v3 license http://www.gnu.org/licenses/gpl-3.0.html

ls -1 *.jpg | while read fn
do
export pa1=`exiv2 "$fn" | grep timestamp | awk '{ print $4 }' | tr ":" "-"`
export pa2=`exiv2 "$fn" | grep timestamp | awk '{ print $5 }' | tr ":" "-"`
export pa="$pa1 $pa2.jpg"
mv "$fn" "$pa"
echo File "$fn" renamed as "$pa"
done

echo All done!

Andy said...

Be careful if you have pics taken within same second - the script as it is now will overwrite all but the last one.

Anonymous said...

Can someone help me with this? The folders I want to run this on are on an external. How do I point the script to the external. Which parts specifically do I paste into Terminal? Thanks

Narcolessico said...

@Anonymous this scripts acts in the current directory, just CD to the directory where the drive is mounted (e.g. "cd /media/user/usbstick").

Post a Comment