zimmertr

Untitled

Mar 5th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.18 KB | None | 0 0
  1. #! /bin/bash
  2. #############################################################################
  3. #############################################################################
  4. ##moveimage.sh is a script to detect the resolution/size of an image and,  ##
  5. ##based on the results, organize it in a new directory. It was created by  ##
  6. ##me to help organize tens of thousands of image files that I recovered    ##
  7. ##from a friend's macbook after she accidentally deleted them so that she  ##
  8. ##wouldn't have to manually parse through them herself.                    ##
  9. #############################################################################
  10. #############################################################################
  11.  
  12. thumb128=0
  13. thumb160=0
  14. thumb200=0
  15. lt20=0
  16. bt20_50=0
  17. bt50_150=0
  18. bt150_500=0
  19. bt500_1024=0
  20. gt1024=0
  21. total=0
  22. iniDate=$(date)
  23.  
  24. echo "Started on: $iniDate"
  25. echo ""
  26. echo ""
  27. #For each image in each subdirectory...
  28. for f in */*.jpg; do
  29.  
  30.     #If the resolution is 128x128, move to thumbnails
  31.     if identify $f | grep 128x128 > /dev/null
  32.         then
  33.             cp $f /media/Data/Recovery/Thumbnails\ \-\ \(128x128\)/ > /dev/null
  34.             echo "$f was copied to Thumbnails (128x128)"
  35.             let thumb128+=1
  36.     fi
  37.  
  38.     #If the resolution is 160x120, move to thumbnails
  39.     if identify $f | grep 160x120 > /dev/null
  40.         then
  41.             cp $f /media/Data/Recovery/Thumbnails\ \-\ \(160x120\)/ > /dev/null
  42.             echo "$f was copied to Thumbnails (160x120)"
  43.             let thumb160+=1
  44.     fi
  45.  
  46.     #If the resolution is 200x200, move to thumbnails
  47.     if identify $f | grep 200x200 > /dev/null
  48.         then
  49.             cp $f /media/Data/Recovery/Thumbnails\ \-\ \(200x200\)/ > /dev/null
  50.             echo "$f was copied to Thumbnails(200x200)"
  51.             let thumb200+=1
  52.     fi
  53.  
  54.     #Else, if the file size is less than 20kb...
  55.     if [[ -n $(find $f -type f -size -20k 2>/dev/null) ]];
  56.         then
  57.             cp $f /media/Data/Recovery/Images\ Between\ 0KB\ and\ 20KB/ > /dev/null
  58.             echo "$f was copied to 0 to 20kb"
  59.             let lt20+=1
  60.     fi
  61.  
  62.     #Else, if the file size is between 20 and 50...
  63.     if [[ -n $(find $f -type f -size +20k -a -size -50k 2>/dev/null) ]];
  64.         then
  65.             cp $f /media/Data/Recovery/Images\ Between\ 20KB\ and\ 50KB/ > /dev/null
  66.             echo "$f was copied to 20 to 50kb"
  67.             let bt20_50+=1
  68.     fi
  69.  
  70.     #Else, if the file size is between 50 and 150...
  71.     if [[ -n $(find $f -type f -size +50k -a -size -150k 2>/dev/null) ]];
  72.         then
  73.             cp $f /media/Data/Recovery/Images\ Between\ 50KB\ and\ 150KB/ > /dev/null
  74.             echo "$f was copied to 50 to 150kb"
  75.             let bt50_150+=1
  76.     fi
  77.    
  78.     #Else, if the file size is between 150 and 500...
  79.     if [[ -n $(find $f -type f -size +150k -a -size -500k 2>/dev/null) ]];
  80.         then
  81.             cp $f /media/Data/Recovery/Images\ Between\ 150KB\ and\ 500KB/ > /dev/null
  82.             echo "$f was copied to 150 to 500kb"
  83.             let bt150_500+=1
  84.     fi
  85.  
  86.     #Else, if the file size is between 500 and 1024...
  87.     if [[ -n $(find $f -type f -size +500k -a -size -1024k 2>/dev/null) ]];
  88.         then
  89.             cp $f /media/Data/Recovery/Images\ Between\ 500KB\ and\ 1MB/ > /dev/null
  90.             echo "$f was copied to 500 to 1024"
  91.             let bt500_1024+=1
  92.     fi
  93.  
  94.     #Else, if the file size is greater than 1024...
  95.                 if [[ -n $(find $f -type f -size +1M 2>/dev/null) ]];
  96.         then
  97.             cp $f /media/Data/Recovery/Images\ Over\ 1MB/ > /dev/null
  98.             echo "$f was copied to over 1024"
  99.             let gt1024+=1
  100.     fi
  101. done;
  102.  
  103. echo ""
  104. echo ""
  105. echo "Summary: "
  106. echo ""
  107. echo "Thumbnails (128x128): $thumb128"
  108. echo "Thumbnails (160x120): $thumb160"
  109. echo "Thumbnails (200x200): $thumb200"
  110. echo "Files less than 20kb: $lt20"
  111. echo "Files between 20kb and 50kb: $bt20_50"
  112. echo "Files between 20kb and 50kb: $bt50_150"
  113. echo "Files between 20kb and 50kb: $bt150_500"
  114. echo "Files between 20kb and 50kb: $bt500_1024"
  115. echo ""
  116. let total=thumb128+thumb160+thumb200+lt20+bt20_50+bt50_150+bt150_500+bt500_1024
  117. echo "Total Files moved: $total"
  118. echo ""
  119. finDate=$(date)
  120. echo "Completed on: $finDate"
Advertisement
Add Comment
Please, Sign In to add comment