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, 7 years and 100 days ago. Viewed 1,641 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
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