#!/bin/bash
# http://www.crystalfaeries.net/linux/bin/timestamp
# Released under GNU LGPL3 2011-08-27 06:58:19+00:00
# This is intended to recursively (*DANGER, DANGER, WILL ROBINSON*)
# find files and rename them with a leading timestamp
echo -n "You are crazy enough to want recursive renaming by timestamps?: "
read answer
if [[ "$answer" == "yes" ]]
then
for prefile in $(find . -type f);do
oldfile=`echo $prefile | sed 's/^\.\///'`
newfile=`basename $oldfile`
datestamp=`stat $oldfile | grep Modify | sed 's/Modify: //' | sed 's/ / /' | sed 's/\..*$//' | cut -f 1`
timestamp=`stat $oldfile | grep Modify | sed 's/Modify: //' | sed 's/ / /' | sed 's/\..*$//' | cut -f 2 | sed 's/:/-/' | sed 's/:/-/'`
mv -i $oldfile $datestamp.$timestamp.$newfile
done
else
echo "decided to play it safe, then."
fi
syntax highlighted by Code2HTML, v. 0.9.1