6

I have recovered images from a lost partition and I need to sort them or put them into a folder by the creating date of the EXIF data of each image

I have installed digiKam and also shotwell but have not found the way to do this on any of the options

Can any one explain to me how to do it with any of those 2 programs or even a new program for Ubutun 13

9

My favorite solution is to set the file date the same as the exif photo date. Doing this, you can sort the files using any file explorer tool.

  1. Install jhead (apt-get install jhead)
  2. Go to the photos directory and run this command jhead -ft *. This will set the file date in the filesystem with the create date of the exif metadata
  3. Now just go to the top menu (in Ubuntu you most go with the mouse through the top of the monitor screen), select View → Sort Images → By Date.
  • Sort Images by Date will order the files by the date they were created or modified. If you just recovered many files all of them are going to have the same DATE. To my understanding the EXIF metadata is inside the file and does not necessarily match the date of the file itself – Mauricio Gracia Gutierrez Jun 11 '15 at 1:49
  • @MauricioGracia stupd me! I thought it used the metadata, but the file data was originaly in the order the photos were taken. Excuse me. I'll delete the answer – neves Jun 12 '15 at 2:51
  • @MauricioGracia: fixed my answer. I – neves Jun 12 '15 at 4:34
4

If you're comfortable using the command line, I recommend using exiftool. Among other things, it does exactly what you're trying to do. There is a bit of a learning curve, but I've spent hours experimenting with test copies of my photos and I'm really glad I did. Link: http://www.sno.phy.queensu.ca/~phil/exiftool/.

To get it, open Terminal and do:

sudo apt-get install exiftool

EDIT: Here's a sample command that renames the files based on creation date in YYYYMMDD format and appends a sequence number at the end. If you read the documentation there's a similar command that copies them into new folders named based on exif data.

exiftool '-filename<CreateDate' -d %Y%m%d%%-.4nc.%%le -r

Hope this helps. Good luck!

  • Scott do I run this command on the folder where the images are located ? Can I run this on a NTFS mounted partition under Ubuntu ? – Mauricio Gracia Gutierrez Jan 13 '14 at 14:00
  • 1
    Obligatory word of warning -- don't try this on your only copy of these photos -- make a backup copy first so that, if you goof it up, you can start over. That said, regarding your questions: Yes, and I think so. For example, if your working copies are stored in /home/me/Pictures/staging, you would do cd /home/me/Pictures/staging first, then invoke exiftool. – Scott Jan 13 '14 at 16:18
  • Will the same command line work for MS Windows ? – Mauricio Gracia Gutierrez Jan 13 '14 at 16:24
  • Based on reading the description on the author's website, I believe so: "ExifTool is a platform-independent Perl library plus a command-line application for reading, writing and editing meta information in a wide variety of files." There might be something special you have to do before you can invoke it from the command prompt in Windows (see under where it says "Windows Executable"), but I would expect all the commands and parameters to be the same in all platforms once you get to that point. – Scott Jan 13 '14 at 16:26
1

Install Phatch Photo batch processor. From the predefined actions, select the one that renames the files with date from exif.

1

Simplest using: jhead -n%Y/%m/%d/%Y%m%d%H%M /Destination/*.jpg

It will sort, move and rename all your JPG's from current directory into nice directory structure with unique filenames /Year/Month/Day/YearMonthDayHourMinute.jpg

It works only on *.jpg files dough, not RAW's

  • Note: it takes files from the path, which is specified at the end of command line : jhead -n%Y/%m/%d/%Y-%m-%d--%H%M-- *.jpg – Vedavrat Jul 30 '17 at 12:10
0

A great tool is Rapid Photo Downloader

  1. Adding the PPA

    sudo apt-add-repository ppa:dlynch3/ppa
    
  2. Updating and installing

    sudo apt-get update
    sudo apt-get install rapid-photo-downloader
    

Use your "lost partition" as input source and configure the target path/filenames based on your exif data in Rapid Photo Downloader

  • The PPA is no longer maintained. Tried to add it and received this message: This PPA is now out-of-date. For the latest version of Rapid Photo Downloader, see damonlynch.net/rapid/download.html – Corey S. Jun 26 '17 at 22:39
0

This is the code I am using. It renames the photos adding YYYYMMDD_originalname.jpg

#! /bin/bash
shopt -s globstar || exit
for PIC in **
do
# look only for jpg
if [[ "$PIC" =~ \.JPG$ ]] || [[ "$PIC" =~ \.jpg$ ]]; then
    # ignore jpg that have 8 numbers at beginning followed by _ or after IMG_ or P_ and followed by _ (already date stamped)
    if [[ "$PIC" =~ [[:digit:]]{8}_.*$ ]] || [[ "$PIC" =~ IMG_[[:digit:]]{8}_.*$] ]] || [[ "$PIC" =~ P_[[:digit:]]{8}_.*$] ]]; then
    :
    else
        # get the date and time from the tag
        DATE=$(exiftool -p '$DateTimeOriginal' "$PIC" | sed 's/[: ]//g')
        echo "file_$PIC"
        # customize date, in this case eliminate the time, getting only the date in 8 numbers and adding _
        DATEMOD2=$(echo $DATE | sed -e 's/^\(.\{8\}\).*/\1_/')
        echo "datemod2_$DATEMOD2"
            # check if DateTimeOriginal was present
            if [[ "$PIC" == "$DATEMOD2$PIC" ]];then
            # as DateTimeOriginal is not present try with HistoryWhen
            DATE=$(exiftool -p '$HistoryWhen' "$PIC" | sed 's/[: ]//g')
            DATEMOD2B=$(echo $DATE | sed -e 's/^\(.\{8\}\).*/\1_/')
            echo "datemod2B_$DATEMOD2B"
                # check if HistoryWhen is present
                if [[ "$PIC" == "$DATEMOD2B$PIC" ]];then
                # nor the tag DateTimeOriginal, nor HistoryWhen present
                echo "skip"
                else
                # this will be done
                echo "mv -i "$PIC" $(dirname "$PIC")/"$DATEMOD2B""$PIC""
                #uncomment if you like it
                #mv -i "$PIC" $(dirname "$PIC")/"$DATEMOD2B""$PIC"
                fi
            else
            # this will be done
            echo "mv -i "$PIC" $(dirname "$PIC")/"$DATEMOD2""$PIC""
            #uncomment if you like it
            #mv -i "$PIC" $(dirname "$PIC")/"$DATEMOD2""$PIC"
            fi
     fi
fi
done

Based on https://www.tuxradar.com/answers/433, https://mikebeach.org/2011/12/17/how-to-retrieve-exif-data-from-the-command-line-in-ubuntu-linux/

See also, http://davehope.co.uk/Blog/sorting-your-photos-with-bash/

EDIT. In this modification, the date in the tag is passed to the name and also to the date attribute with touch. Also, if those tags do not exist, the date of modification tag is passed to the name of the file.

#! /bin/bash
shopt -s globstar || exit
for PIC in **
do
# look only for jpg
if [[ "$PIC" =~ \.JPG$ ]] || [[ "$PIC" =~ \.jpg$ ]]; then
        echo "file_$PIC"
        # get the date and time from the tag DateTimeOriginal
        DATE=$(exiftool -p '$DateTimeOriginal' "$PIC" | sed 's/[: ]//g')
        LONGDATE=$(echo $DATE | sed -e 's/^\(.\{12\}\).*/\1/')
            # check if DateTimeOriginal is 0000... OR empty
            if [[ "$LONGDATE" != "000000000000" ]] && [[ -n "$LONGDATE" ]]; then
            echo "datetimeoriginal_$LONGDATE"
            # modify the attribute date with the info in the tag date
            touch -t $LONGDATE "$PIC"
            # customize date, in this case eliminate the time, getting only the date in 8 numbers and adding _
            DATEMOD2=$(echo $DATE | sed -e 's/^\(.\{8\}\).*/\1_/')
            echo "datemod2_$DATEMOD2"
                    # skip renaming if
                    # 8 numbers at beginning followed by _ or after IMG_ or P_ and followed by _ (already date stamped)
                    if [[ "$PIC" =~ [[:digit:]]{8}_.*$ ]] || [[ "$PIC" =~ IMG_[[:digit:]]{8}_.*$] ]] || [[ "$PIC" =~ P_[[:digit:]]{8}_.*$] ]]; then
                    :
                    else
                    # this will be done

                    filename=$(basename "$PIC")
                    echo "$filename"
                    echo "mv -i \""$PIC"\" \""$(dirname "$PIC")"/"$DATEMOD2""$filename"\""
                    #uncomment if you like it
                    mv -i "$PIC" "$(dirname "$PIC")/$DATEMOD2$filename"

                    fi
            else
            # get the date and time from the tag HistoryWhen

            DATE=$(exiftool -p '$HistoryWhen' "$PIC" | sed 's/[: ]//g')
            LONGDATE=$(echo $DATE | sed -e 's/^\(.\{12\}\).*/\1/')

            # check if Historywhen is 0000... or empty
                if [[ "$LONGDATE" != "000000000000" ]] && [[ -n "$LONGDATE" ]]; then
                echo "historywhentag_$LONGDATE"

                touch -t $LONGDATE "$PIC"
                DATEMOD2B=$(echo $DATE | sed -e 's/^\(.\{8\}\).*/\1_/')
                echo "datemod2B_$DATEMOD2B"

                    if [[ "$PIC" =~ [[:digit:]]{8}_.*$ ]] || [[ "$PIC" =~ IMG_[[:digit:]]{8}_.*$] ]] || [[ "$PIC" =~ P_[[:digit:]]{8}_.*$] ]]; then
                    :
                    else
                    # this will be done             
                    filename=$(basename "$PIC")
                    echo "$filename"
                    echo "mv -i \""$PIC"\" \""$(dirname "$PIC")"/"$DATEMOD2B""$filename"\""
                    #uncomment if you like it
                    mv -i "$PIC" "$(dirname "$PIC")/$DATEMOD2B$filename"
                    fi

                else
                    # get the date and time from the tag tag filemodifydate

                    DATE=$(exiftool -p '$filemodifydate' "$PIC" | sed 's/[: ]//g')
                    LONGDATE=$(echo $DATE | sed -e 's/^\(.\{12\}\).*/\1/')

                    # check if filemodifydate is 0000... or  empty
                    if [[ "$LONGDATE" != "000000000000" ]] && [[ -n "$LONGDATE" ]]; then
                    #echo "filemodifydatetag_$LONGDATE"

                    #touch -t $LONGDATE "$PIC"
                    DATEMOD2C=$(echo $DATE | sed -e 's/^\(.\{8\}\).*/\1_/')
                    echo "datemod2C_$DATEMOD2C"

                        if [[ "$PIC" =~ [[:digit:]]{8}_.*$ ]] || [[ "$PIC" =~ IMG_[[:digit:]]{8}_.*$] ]] || [[ "$PIC" =~ P_[[:digit:]]{8}_.*$] ]]; then
                        :
                        else
                        # this will be done             
                        filename=$(basename "$PIC")
                        echo "$filename"
                        echo "mv -i \""$PIC"\" \""$(dirname "$PIC")"/"$DATEMOD2C""$filename"\""
                        #uncomment if you like it
                        mv -i "$PIC" "$(dirname "$PIC")/$DATEMOD2C$filename"
                        fi

                    else

                    echo "Error, NO date available"
                    fi
                fi
            fi
fi
done

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.