Home > Digital Image Processing, Linux > Batch sort jpg images to folders named after dates images were taken

Batch sort jpg images to folders named after dates images were taken

Once in a while I need to transfer pictures taken with my mobile phone for private use (jpg format) from my phone to my PC – and to sort them there. I want my pictures sorted in folder named by the date taken (e.g. “2014_05_11_description”) – which is pretty time consuming if done by hand. The script snippet below takes all jpg files in the current folder, creates subfolders named by the dates pictures have been taken and sorts the files in there accordingly. In case you don’t want to add a description to the folders afterwards you might want to remove the last “_” in foldername.

for f in `ls *jpg`
do
        foldername=`exif -t 0x9003 -m $f | sed s/:/_/g | awk '{print $1}'`_
        if ! test -e "$foldername"; then
                mkdir -pv "$foldername"
        fi
        mv -v $f $foldername
done

Insights to extracting date from jpg files in short:

  • exif is used to extract the date and time the image was taken,
  • sed replaces “:” with “_” and
  • awk removes the time information as I only want date.

Credits: according to my notes I originally built my script upon this script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: