sxiii

FileSize Sort Script will help you after HDD recovery

Mar 14th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ####################################################################################################
  4. # FileSize Sort Script (FS3) by Security XIII; 15.03.2013
  5. # Another script name: Find & Sort Out Important Files After HDD Recovery (with photorec)
  6. # This script arranges all files in current and recursive folders into the following scheme:
  7. # One folder for each filesize range:
  8. # less than 10kb, 10kb to 50kb, 50kb to 100kb, 100kb to 300kb,
  9. # 300kb to 500kb, 500kb to 1mb, 1mb to 3mb, and larger than 3 mb.
  10. # This is quite comfortable to find important files after HDD recovery.
  11. # Just put the file in the folder you want it to work, do chmod +x sort.sh, run like "./sort.sh"
  12. # Note: it will create separate folders inside each folder you have under its (script) "." location
  13. # Note 2: it will also name this folders with postfix of $i, which is just counter
  14. ####################################################################################################
  15.  
  16. echo "Sorting script started."
  17. echo "Parsing directory to file dir.list"
  18. ls -d */ > dir.list
  19. total=$(cat dir.list | wc -l)
  20. echo "Found $total directories."
  21. i=0
  22.  
  23. cat dir.list | while read line; do
  24.  
  25. let i++
  26. echo "Entering directory #$i of $total: $line"
  27. cd $line
  28.  
  29.  
  30. for file in ./*; do
  31. fs=$(stat -c '%s' $file)
  32. if [ "$fs" -gt "3000000" ]; then mkdir -p "large-$i" && mv "${file}" "large-$i"; fi
  33. if [ "$fs" -lt "3000000" -a $fs -gt "1000000" ]; then mkdir -p "3mb-$i" && mv "${file}" "3mb-$i"; fi
  34. if [ "$fs" -lt "1000000" -a $fs -gt "500000" ]; then mkdir -p "1mb-$i" && mv "${file}" "1mb-$i"; fi
  35. if [ "$fs" -lt "500000" -a $fs -gt "300000" ]; then mkdir -p "500kb-$i" && mv "${file}" "500kb-$i"; fi
  36. if [ "$fs" -lt "300000" -a $fs -gt "100000" ]; then mkdir -p "300kb-$i" && mv "${file}" "300kb-$i"; fi
  37. if [ "$fs" -lt "100000" -a $fs -gt "50000" ]; then mkdir -p "100kb-$i" && mv "${file}" "100kb-$i"; fi
  38. if [ "$fs" -lt "50000" -a $fs -gt "10000" ]; then mkdir -p "50kb-$i" && mv "${file}" "50kb-$i"; fi
  39. if [ "$fs" -lt "10000" ]; then mkdir -p "small-$i" && mv "${file}" "small-$i"; fi
  40. done
  41.  
  42. cd ..
  43.  
  44. done
  45.  
  46. echo "Sorting script finished, parsed & sorted $total directories."
Advertisement
Add Comment
Please, Sign In to add comment