php
Random Rename file with md5 Hash [Scripts]
Submitted by shawn on Tue, 06/29/2010 - 22:06Sometimes I find it handy to randomly rename files with md5 hashes. Don't you ever feel like you need to do that? This script involves a line of PHP so to use it make sure you have PHP installed on your system.
It accepts either a file or a wildcard glob such as '*.jpg' (no quotes).
#!/bin/bash
while [ $# -gt 0 ]
do
if [ -f "${1}" ]; then
sz_basename=`basename "${1}"`
sz_dirname=`dirname "${1}"`
NEW_FILE=`php -r "echo md5('$sz_basename'.mt_rand());"`.${sz_basename#*.}
echo "$1 => ${sz_dirname}/${NEW_FILE}"
mv "$1" ${sz_dirname}/${NEW_FILE}
fi
shift
done
