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 “_” andawk
removes the time information as I only want date.
Credits: according to my notes I originally built my script upon this script.
