🦍 maniedzi's blog

Storing photos

I have the digital camera for about 20 years now. My photo collection is near 140GB - mostly personal and family pictures, ton of pictures of my kids. To handle it somehow, I had to have some workflow for storing them.

Over the year I have found one way to keep them organised. The main directory structure includes directories named by the year (2001, 2002, n), when the picture was taken. Each year has subdirectories named with the date and description. For example: 2015/20151011-Auntie_Birthday 1.

All the pictures inside those directories have the original file name given by the camera with the suffix including date and hour when it was taken. For example: PXB0001_20050111_1050.jpg using the YYYYMMDD_HHMI format.

Below is the script I am using to automate adding the suffix to the files. It is not masterpiece of programming, but it works.

#!/bin/sh

FIND_CMD=$(find . -type f -and -iname "*.jpg" -or -iname "*.png" -or -iname "*.cr2" 2> /dev/null | sed -e "s/^\.\///g")

for file in $FIND_CMD; do
    echo ${file}
    file_name=${file%.*}
    file_ext=${file#*.}
    file_date=`stat -c %x ${file} | cut -d. -f1 | sed 's/-//g' | sed 's/://g' | sed 's/ /_/g' | cut -c 1-13`
    new_file_name=${file_name}_${file_date}.${file_ext}
    echo "Renaming ${file} to ${new_file_name}..."
    mv ${file} ${new_file_name}
    echo ""
done

Here some of the "magic" explained:


There is an RSS feed for this blog.


  1. Let's make it clear. I'm Polish, so the folder name is not in English. 😀

#life