#!/bin/bash
# (c) whitequark 2010
set -e
if [ $# != 2 ]; then
echo "Usage: $0 <filename> <part size>"
echo " This script will split file to multiple parts, starting from"
echo " the end, and truncating the original file in process."
echo " Part size is specified in bytes."
echo " Use at your own risk."
exit 0
fi
filename=$1
partsize=$2
size=$(stat -c '%s' "${filename}")
parts=$(($size / $partsize))
do_split() {
_part=$1
_size=$2
echo "Splitting part $_part"
echo $(($partsize * ($_part - 1)))
dd if="${filename}" of="${filename}.$(printf '%04d' $_part)" \
count=1 bs=$partsize skip=$(($_part - 1))
echo "Truncating source file"
truncate "${filename}" --size="-$_size"
}
lastsize=$(($size % $partsize))
if [ $lastsize != 0 ]; then
do_split $(($parts + 1)) $lastsize
fi
for i in $(seq $parts -1 1); do
do_split $i $partsize
done
rm "${filename}"
O gedit correu com sucesso após desmontá-lo e montá-lo novamente.