image ordering by Original Date Time using bash script

Here is the script:

#!/bin/bash -
#          FILE:
#         USAGE: ./
#       OPTIONS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---

for i in *
    if [[ $(file $i) == *image* ]] 
        echo "Image file is :: $i"
        dir=$( exiftool -s -DateTimeOriginal $i | awk -F':' '{print $2"/"$3}')
        mkdir -p $dir
        cp $i $dir/
        echo "Excluding $i"


Script looks at the DateTimeOriginal parameter in output of exiftools ( which is basically the date and time image was taken) and then puts the images in the folder in format YYYY/MM.

Get count of lines in scripts (shell)

If you have tried to get the count of lines in file, the you would know about “nl” or “wc -l”. But as you are aware these give you number of lines with other details as well and you need to post process the number to make sure that you have only number and nothing else. In such cases, it is useful to use the count feature of grep and here is a shorthand to get the count of lines in any shell script:

lines=$(grep -c . <filename>)

Filename handling with space and newline character.

[Novalug] Filename handling: correctness vs. convenience has a nice post from Michael Henry on Filename handling.