For When You Can't Have The Real Thing
[ start | index | login ]
start > Rename All Files To Be Their MD5Sum Values

Rename All Files To Be Their MD5Sum Values

Created by dave. Last edited by dave, one year and 39 days ago. Viewed 419 times. #3
[diff] [history] [edit] [rdf]


I have a ton of randomly named pictures. To make them consistently inconsistent, I want the on-disk filename to be the md5sum of the file content. (This acts as a paper-bag way of detecting gross duplicates. Doing less gross-duplicate-detection is left as an exercise for the reader's google skillz.)

Oh, and the file names have spaces in them.


This renames all files in the current directory to be the md5sum of their contents, preserving the file extension. There's probably a clever one-liner that does this but I'm tired and this works for me.

IFS=$(echo -en "\n\b")
for i in *
  EXT=`echo $i | sed -e 's/^.*\./\./'`
  SUM=`md5sum $i |awk '{print $1}'`
  if [ -e "$SUM$EXT" ] ; then
    echo -n !
    echo -n .
    mv $i $SUM$EXT
# restore $IFS
no comments | post comment

Virtual Dave Megaplex:

Internet Explorer 6 Users >>Click Here

(read this note about local search)

Logged in Users: (0)
… and 10 Guests.

Editing: snipsnap-help, Image Macro

(Et auditum est, et idcirco ego nunc simulare)

Installed 7 years and 37 days ago
Powered By >>SnipSnap Version 1.0b1-uttoxeter

This is a collection of techical information, much of it learned the hard way. Consider it a lab book or a /info directory. I doubt much of it will be of use to anyone else.

Useful: | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt