Created
May 11, 2016 05:11
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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