Move files by date into different directory using CLI

A while back I was unfortunate in such a way that my HDD that I primarily use as photo archive started having mechanical issues, and before It died on my arms I had the opportunity to backup most of my pictures, however most of them were truncated and had to be discarded and the ones I could recover their filenames where overwritten with random filenames and ascii codes.

For over a while I have neglected my pictures and they just piled up in a single and nameless directory, until I took it against myself to clean them up.

And one of the benefits of using Linux OS is the scripting features.

for i in *; 
do d=$(exiftool $i | grep 'Date/Time Original' | cut -f 17 -d ' '); 
newd=`echo ${d//:/-}`; 
echo $i ${newd} ;
mkdir -p ${newd}; 
mv -- ${i} ${newd}; 
done
  1. write this script to a file named mvByDate.sh in your old directory.
  2. replace the /your/new/directory with your new directory’s path
  3. make this file executable with chmod +x mvByDate.sh
  4. then execute this file by ./mvByDate.sh
  5. voila
Advertisements

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