Skip to content

Instantly share code, notes, and snippets.

@dannyflax
Created May 11, 2016 05:11
Show Gist options
  • Save dannyflax/6b1ef1b4348c20d79e2b85acad5b388d to your computer and use it in GitHub Desktop.
Save dannyflax/6b1ef1b4348c20d79e2b85acad5b388d to your computer and use it in GitHub Desktop.
Partitions a file into X different parts to reduce the file size. Partitions can be concatenated back together by placing them in the same directory and running cat * > originalFile.
#!/bin/bash
file="$1"
num=$2
size="$(wc -c < $file | tr -d '[[:space:]]')"
count="$(expr $size / $num)"
count="$(expr $count + 1)"
for k in $(seq 1 $num); do
i="$(expr $k - 1)"
n="$(expr $i \* $count)"
name="$(echo $file)_file_part_$k"
echo "Writing $count bytes to $name starting at $n"
dd if=$file of=$name bs=1 count=$count skip=$n
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment