If a single file becomes too large, e.g., in order to be sent via mail, you may want to split it into parts.
The command line tool tar is perfectly suitable for this, as it stems from an era where backups were regularly performed using tape drives (which have a certain size limit, of course). We will “misuse” this capability of tar in the following.
I suppose your file is called large_file.tar and you want to split it into parts of size 5MB (= 5120KB). The following instructions are not limited to tar files, any single file will do fine as well.
Splitting up the File
You start creating the archive with the following command:
tar -c -M --tape-length 5120 --file=split_archive_part1.tar large_file.tar
As long as there is some unprocessed portion of the original file, you will be prompted for more “volumes”, i.e., more tapes. If you’d use a tape drive, you would now switch the tape, but in our setting we give an additional file for the second part by responding as follows (note the preceeding “n ” in front of the file name):
Prepare volume #2 for `split_archive_part1.tar' and hit return: n split_archive_part2.tar
For a 22.5MB large file the whole procedure already becomes quite tedious:
tar -c -M --tape-length 5120 --file split_archive_part1.tar large_file.tar
Prepare volume #2 for `split_archive_part1.tar' and hit return: n split_archive_part2.tar
Prepare volume #3 for `split_archive_part2.tar' and hit return: n split_archive_part3.tar
Prepare volume #4 for `split_archive_part3.tar' and hit return: n split_archive_part4.tar
Prepare volume #5 for `split_archive_part4.tar' and hit return: n split_archive_part5.tar
This question-answer game will continue until the whole file has been processed. If you want to save space, you may now compress the resulting archives:
gzip -c split_archive_part1.tar > split_archive_part1.tar.gz && rm split_archive_part1.tar
gzip -c split_archive_part2.tar > split_archive_part2.tar.gz && rm split_archive_part2.tar
# and so on...
Merging the Fragments
Of course, you (or the person who receives the fragmented archive from you) need to be able to restore the original file. The “mirror-symmetric” command to tar -c is tar -x:
tar -x -M --file=split_archive_part1.tar
The following procedure is identical to the other direction. If you use the compressed fragmented archives, you still need to decompress each of them:
gzip -d split_archive_part1.tar.gz
Afterwards the fragmented archives are merged in order to restore the original file:
tar -x -M --file=split_archive_part1.tar
Prepare volume #2 for `split_archive_part1.tar' and hit return: n split_archive_part2.tar
Prepare volume #3 for `split_archive_part2.tar' and hit return: n split_archive_part3.tar
Prepare volume #4 for `split_archive_part3.tar' and hit return: n split_archive_part4.tar
Prepare volume #5 for `split_archive_part4.tar' and hit return: n split_archive_part5.tar
You should now see large_file.tar in the same directory.
Credits
Thanks to Paul Bradly, who described this procedure on his site.