Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ####################################################################################################
- # FileSize Sort Script (FS3) by Security XIII; 15.03.2013
- # Another script name: Find & Sort Out Important Files After HDD Recovery (with photorec)
- # This script arranges all files in current and recursive folders into the following scheme:
- # One folder for each filesize range:
- # less than 10kb, 10kb to 50kb, 50kb to 100kb, 100kb to 300kb,
- # 300kb to 500kb, 500kb to 1mb, 1mb to 3mb, and larger than 3 mb.
- # This is quite comfortable to find important files after HDD recovery.
- # Just put the file in the folder you want it to work, do chmod +x sort.sh, run like "./sort.sh"
- # Note: it will create separate folders inside each folder you have under its (script) "." location
- # Note 2: it will also name this folders with postfix of $i, which is just counter
- ####################################################################################################
- echo "Sorting script started."
- echo "Parsing directory to file dir.list"
- ls -d */ > dir.list
- total=$(cat dir.list | wc -l)
- echo "Found $total directories."
- i=0
- cat dir.list | while read line; do
- let i++
- echo "Entering directory #$i of $total: $line"
- cd $line
- for file in ./*; do
- fs=$(stat -c '%s' $file)
- if [ "$fs" -gt "3000000" ]; then mkdir -p "large-$i" && mv "${file}" "large-$i"; fi
- if [ "$fs" -lt "3000000" -a $fs -gt "1000000" ]; then mkdir -p "3mb-$i" && mv "${file}" "3mb-$i"; fi
- if [ "$fs" -lt "1000000" -a $fs -gt "500000" ]; then mkdir -p "1mb-$i" && mv "${file}" "1mb-$i"; fi
- if [ "$fs" -lt "500000" -a $fs -gt "300000" ]; then mkdir -p "500kb-$i" && mv "${file}" "500kb-$i"; fi
- if [ "$fs" -lt "300000" -a $fs -gt "100000" ]; then mkdir -p "300kb-$i" && mv "${file}" "300kb-$i"; fi
- if [ "$fs" -lt "100000" -a $fs -gt "50000" ]; then mkdir -p "100kb-$i" && mv "${file}" "100kb-$i"; fi
- if [ "$fs" -lt "50000" -a $fs -gt "10000" ]; then mkdir -p "50kb-$i" && mv "${file}" "50kb-$i"; fi
- if [ "$fs" -lt "10000" ]; then mkdir -p "small-$i" && mv "${file}" "small-$i"; fi
- done
- cd ..
- done
- echo "Sorting script finished, parsed & sorted $total directories."
Advertisement
Add Comment
Please, Sign In to add comment