The linux way to do things

Organize your pictures according to the date they were taken

When it comes to manage my pictures library, I must admit I am very undisciplined. I usually let pass many months between the time I take a picture and the time I transfer it to my computer so it is very hard to organize them by the date they were taken. Moreover, I am sometimes in a hurry so I just transfer them in a “temporary” place telling myself that I will organize them later (sure…).

In short, for years, my pictures library has been a total mess. Lately, I wanted to see my child evolution through years and months to finally quickly realize that my neglicence has made this simple task now impossible. In the end, all I wanted was to organize them by the date they were taken, not by the event they were attached to.

I recently solved my problem by writing a short bash script that does exactly that. First the script scans a source folder looking for jpg or jpeg files. Now for each file found, the script will look at his EXIF information (if it is not possible, the creation date of the file will then be used) to determine the date it was taken and copy it in a destination folder in an organized way using a Year, Month and Date format.  Files with the same name will be automatically renamed and you can choose to copy (default) or  instead move the pictures found.

The basic usage is the following one:

[hudony@fedh ~]$ ./ -h
Usage: ./ [-moqh] SOURCE DESTINATION
-m Use move instead of copy
-o Overwrite duplicate files instead of renaming them
-q Quiet, do not display informations on the console
-h This help message

Here is an concrete example:

First the folder containing the pictures I need to organize

I then execute the script:

[hudony@fedh ~]$ ./ /tmp/src /tmp/dest
Searching for pictures… 27 pictures found
Processing pictures… This can take a while
`/tmp/src/IMG_1744.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_10/IMG_1744.jpg’
`/tmp/src/IMG_1768.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_18/IMG_1768.jpg’
`/tmp/src/IMG_1791.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1791.jpg’
`/tmp/src/IMG_1787.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1787.jpg’
`/tmp/src/IMG_1762.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1762.jpg’
`/tmp/src/IMG_1763.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1763.jpg’
*** /tmp/src/image.jpg has no EXIF data, using creation date : `/tmp/src/image.jpg’ -> `/tmp/dest/2013/2013_02/2013_02_05/image.jpg’
`/tmp/src/IMG_1766.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_18/IMG_1766.jpg’
`/tmp/src/IMG_1788.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1788.jpg’
`/tmp/src/IMG_1790.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1790.jpg’
`/tmp/src/IMG_1760.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1760.jpg’
`/tmp/src/IMG_1740.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_10/IMG_1740.jpg’
`/tmp/src/IMG_1764.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1764.jpg’
`/tmp/src/IMG_1711.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_07/IMG_1711.jpg’
`/tmp/src/IMG_1742.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_10/IMG_1742.jpg’
`/tmp/src/IMG_1780.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1780.jpg’
`/tmp/src/IMG_1769.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_18/IMG_1769.jpg’
`/tmp/src/IMG_1767.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_18/IMG_1767.jpg’
`/tmp/src/IMG_1712.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_07/IMG_1712.jpg’
`/tmp/src/IMG_1743.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_10/IMG_1743.jpg’
`/tmp/src/IMG_1789.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_21/IMG_1789.jpg’
`/tmp/src/IMG_1710.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_07/IMG_1710.jpg’
`/tmp/src/IMG_1713.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_07/IMG_1713.jpg’
`/tmp/src/IMG_1741.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_10/IMG_1741.jpg’
`/tmp/src/IMG_1765.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1765.jpg’
`/tmp/src/IMG_1761.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_17/IMG_1761.jpg’
`/tmp/src/IMG_1714.jpg’ -> `/tmp/dest/2012/2012_03/2012_03_07/IMG_1714.jpg’
+ 27 pictures transferred
Finished! A log file called organizePictures.log has been created

Then the results from /tmp/dest :

The script contains 2 files that must reside in the same directory.  Just copy (and rename them to .sh) them anywhere in your filesystem and execute as described above

Be Sociable, Share!

Categorised as: Bash

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>