Linux Rename using Modified Date

I know I’m going to forget how I did this again, especially if I lose the following script I wrote, so I’m posting it here.  Here’s the gist: a directory full of files and I want to to copy them to a new location while also changing them to lower-case, using a different extension (MOD => mpg), and finally including the Last Modified date in the name (YYMMDD-hhmmss).

#! /bin/bash
for file in $1/*.MOD
do
   modifdate=`stat -c %y $file`
   formatdate=`date -d "$modifdate" "+%Y%m%d-%0k%M%S"`
   echo "cp -p -u $file $2/mov-$formatdate.mpg"
   cp -p -u $file $2/mov-$formatdate.mpg
done

Note to myself: you called it movcp and put it in /usr/bin. Thus I go from this …

Raw video files from SD card for my Canon FS100

Raw video files from SD card for my Canon FS100

Using this …

Linux script copying files off Canon FS100 SD and adding timestamp to their name.

Linux script copying files off Canon FS100 SD and adding timestamp to their name.

To this:

Canon FS100 files are just MPEG-2 without proper aspect ratio header set

Canon FS100 files are just MPEG-2 without proper aspect ratio header set

Voila! Now I can archive these off to my ReadyNAS and online backup.

Leave a Reply