IsraelTorres

urename.sh

Oct 14th, 2011
125
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.2
  6. #
  7. # Syntax:
  8. #   urename.sh
  9. #
  10. # Purpose:
  11. #   Rename files to their MD5 hash and remove all duplicates
  12.  
  13. totalFiles=$(ls -1 | wc -l)
  14.  
  15. selfScript=$(md5deep -q urename.sh | cut -c -32)
  16.  
  17. for zFile in *; do
  18.     fileExt=$(echo $zFile | awk -F . '{if (NF>1) {print "."$NF}}')
  19.    
  20.     mv -f -- "$zFile" "$(md5deep -q -- "$zFile" | cut -c -32)$fileExt" 2> /dev/null
  21. done
  22.  
  23. rm -rf $selfScript.sh
  24.  
  25. reducedFiles=$(ls -1 | wc -l)
  26.  
  27. echo Original File Count: $totalFiles
  28. echo Reduced File Count: $reducedFiles
RAW Paste Data