Split & Merge Files in Solaris

Use split to divide a large file into ordered pieces, then concatenate those pieces to reconstruct the original.

Split a file

split -b 3m test.zip splitfile
ls -l splitfile*

On the Solaris command shown here, 3m means 3 × 1,048,576 bytes per piece, except for a potentially smaller final piece. A file exactly 12 MiB long produces four 3 MiB pieces, not three 4 MiB pieces.

Reassemble the pieces

For four pieces with the default alphabetic suffixes:

cat splitfileaa splitfileab splitfileac splitfilead > test1.zip

Include every piece in its original order. A wildcard can also work when the directory contains only the intended pieces:

cat splitfile* > test1.zip

Use an output filename that cannot match the input pattern. Compare the reconstructed file with the original, or compare checksums, before deleting any pieces.

Reference: Oracle: split(1).

You May Also Like

Leave a Reply?