IsraelTorres

urename.sh

Oct 14th, 2011
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # Author: Erik Musick
  4. # Date: 2011.10.13
  5. # Version: 0.3
  6. #
  7. # Syntax:
  8. #   urename.sh
  9. #
  10. # Purpose:
  11. #   Rename files to their MD5 hash and remove all duplicates
  12. #      20111014:IT: Added audit log to match hash with old filename for tracking
  13.  
  14. totalFiles=$(ls -1 | wc -l)
  15. selfScript=$(md5deep -q urename.sh | cut -c -32)
  16. auditfile='auditlog.txt'
  17.  
  18. for zFile in *; do
  19.     fileExt=$(echo $zFile | awk -F . '{if (NF>1) {print "."$NF}}')
  20.         yFile=$(md5deep -q -- "$zFile" | cut -c -32)$fileExt
  21.         echo -e "$yFile\t$zFile" >> $auditfile
  22.     mv -f -- "$zFile" "$yFile" 2> /dev/null
  23. done
  24.  
  25. rm -rf $selfScript.sh
  26.  
  27. reducedFiles=$(ls -1 | wc -l)
  28.  
  29. echo Original File Count: $totalFiles
  30. echo Reduced File Count: $reducedFiles
  31.  
RAW Paste Data