Shell script to organize your pictures
This is a small shell script I use to organize my pictures.
I usually download pictures from my digital camera to a folder and from time to time I want to put them in the folder corresponding to the date I took them. This script reads the EXIF data from the pictures and copies them to where they belong. The directory structure looks like this:
Year
Month 1
Day 1
Day 2
Month 2
Day 1
and so on
1 2 3 4 5 6 7 8 9 10 11 12 | #!/bin/sh from=/home/pctips/jpg to=/home/pctips/pictures find $from -iname '*jpg' | while read FILENAME do year=`exiftool "$FILENAME" | awk '/Date\/Time Original/ {print $4}'|cut -f1 -d':'` month=`exiftool "$FILENAME" | awk '/Date\/Time Original/ {print $4}'|cut -f2 -d':'` day=`exiftool "$FILENAME" | awk '/Date\/Time Original/ {print $4}'|cut -f3 -d':'` target=$to/$year/$month/$day mkdir -p $target cp "$FILENAME" $target done |
It doesn’t check if the folder exists, just tries to create it, so it can be updated to verify if that folder exists.
You just have to edit from and to and write your source folder and destination folder.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





July 2nd, 2009 at 12:12 pm
[code type=bash]
...
cd $to
find $from -iname '*jpg' |
xargs exiftool |
awk '/File Name/{f=$4} /Date\/Time Original/ {p=gensub(":","/","g",$4);print "mkdir -p p; cp "f" "p}' |
sh
[/code]