photos.sh
unload and file photos from a camera.. . digital of course
the use of this script is to copy (or move) photos from a camera (mounted as a regular mass storage device) to a folder filing system organised by date.. . (each photo gets a folder with it's date).. . . you will need for this to work exiv2 so do install this before using the script.
what this should do
to properly use this script :
- go into the folder where the photos arrive, normally this would be on the camera itself however you can actually use this script to reorganize already taken photos of course.
- execute the script "photo_save.sh"
the script will :
- for each photo taken (including in child folders (although there is an option for this)
- figure out the date when the picture was taken through EXIF
- create a folder with the date and put the photo in it
configuration options
a resumé of the available options :
- UNLOAD : this is where you determine the base folder where things will go
- METHOD : here you can decide if you want the script to be recursif or not
- EXTENSIONS : depending on the method you chose the syntax will change, use the examples to suit to your taste (and needs)
i personally use a copy of the script for each camera, so i rename the script to photo-save-d50.sh for my "D50".. .. .. of course here you do what you want obviously...
the script
you can download the script with this link or copy paste it from below . .. .. .
#!/bin/bash
# script designed to help unload photos from camera/cd/or_whatever
# to folders ordered by date based on EXIF info.
# USAGE: cd /to/the/folder/where/the/files/are
# sh photo-save.sh
# DEPENDS on: exiv2
# HINTS: if you have multiple cameras you can:
# - copy this script accordingly: ex. cp photo-save.sh photo-save-d50.sh
# - make sure that UNLOAD parameter is set: ex. /home/user/unload/d50/
# - now use photo-save-d50.sh instead of photo-save.sh
# - repeat the same for as many cameras you need to..
# if you didn't already know, you can chmod +x photo-save.sh and copy it
# to a "bin" folder (ex /usr/local/bin/)
#
# AUTHOR: Emmanuel REVAH manu-AT-manurevah.com http://manurevah.com/
# i'm not sure about a licence so whatever, just don't sue me.. . ... :]
# o/
# root folder for unloading pictures to
UNLOAD='/home/manu/toph/unload/d50/'
# the script can either work on files in current directory OR
# work on files in current directory AND recursively
# 1=current ; 2=recursive
METHOD=2
if [ ${METHOD} == 1 ]; then
# Methode 1 options
# types of files we want to move/copy (space separated values)
# HINT: you might need to add uppercase extensions
EXTENSIONS="*.jpg *.nef"
# list files based on EXTENSIONS
FILETYPES=`ls ${EXTENSIONS} 2>/dev/null`
fi
if [ ${METHOD} == 2 ]; then
# Method 2 options
# you'll have to add the extensions accordingly
# default line (you can replace "name" by "iname" for removing case sensitivity)
# FILETYPES=`find . -name "*.jpg" -or -name "*.nef"`
FILETYPES=`find . -name "*.jpg" -or -name "*.nef"`
# avec regex: find ./ -regex ".*(jpg|nef)$"
fi
# for every file we will find out the EXIF date and put the file into the
# apropriate dated folder (created if needed)
for i in ${FILETYPES}; do
YEAR=`exiv2 $i 2>/dev/null |grep timestamp|cut -d " " -f 4|cut -c 1-4`
MONTH=`exiv2 $i 2>/dev/null |grep timestamp|cut -d " " -f 4|cut -c 6,7`
DAY=`exiv2 $i 2>/dev/null |grep timestamp|cut -d " " -f 4|cut -c 9,10`
WHEREIGO=${UNLOAD}/${YEAR}/${MONTH}_${YEAR}/${DAY}_${MONTH}_${YEAR}
# test if value year is empty
if [ -z ${YEAR} ]
then
echo "$i: No Exif data found in the file"
else
mkdir -p ${WHEREIGO}
cp $i ${WHEREIGO}
fi;
done
exit