SHARE
TWEET

Script limpiar RAWs huérfanos

aremesal Dec 19th, 2016 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Uso: limpia_raws.sh [[path] [[extension] [extensionjpg]]]
  4. # Sin parametros toma el path actual, DNG y JPG respectivamente
  5.  
  6. UNITSLOOP=0
  7. UNITS=("B" "KB" "MB" "GB")
  8.  
  9. TAM=0
  10. COUNT=0
  11.  
  12. function humantam {
  13.     if [[ $1 -gt 1024 ]]; then
  14.         UNITSLOOP=`expr $UNITSLOOP + 1`
  15.         AUX=`echo "$1/1024" | bc`
  16.         humantam $AUX
  17.     else
  18.         TAM=$1
  19.     fi
  20. }
  21.  
  22. WHERE=`pwd`
  23. # Olympus: RAWEXT='ORF'
  24. # Panasonic: RAWEXT='RW2'
  25. # Fuji: RAWEXT='RAF'
  26. RAWEXT='DNG'
  27. JPGEXT='JPG'
  28. XMPEXT='xmp'
  29.  
  30. if [[ $# -eq 1 ]]; then
  31.     if [[ $1 = "-h" ]]; then
  32.         echo -e "Uso: limpia_raws.sh [[path] [[extension] [extensionjpg]]]"
  33.         exit 0
  34.     fi
  35. fi
  36.  
  37. if [[ $# -ge 1 ]]; then
  38.     WHERE=$1
  39. fi
  40.  
  41. if [[ $# -ge 2 ]]; then
  42.     RAWEXT=$2
  43. fi
  44.  
  45. if [[ $# -ge 3 ]]; then
  46.     JPGEXT=$3
  47. fi
  48.  
  49. cd "$WHERE"
  50.  
  51. for i in `ls *.$RAWEXT`; do
  52.     AUX=`echo $i | sed s/$RAWEXT/$JPGEXT/`
  53.     if [[ ! -f $AUX ]]; then
  54.         COUNT=`expr $COUNT + 1`
  55.         AUXTAM=`ls -l $i | cut -f 5 -d' '`
  56.         TAM=`expr $TAM + $AUXTAM`
  57.         echo -e "Borramos $i"
  58.         rm $i
  59.     fi
  60. done
  61.  
  62. humantam $TAM
  63.  
  64. echo -e "Borrados $TAM${UNITS[$UNITSLOOP]} en $COUNT archivos"
RAW Paste Data
Top