Mac OS and file splitting

It’s often useful to be able to split big archived files into smaller chunks, move them to – say – an external FAT32 hard drive (that won’t take anything bigger than 4Gb), and then recompose the original by combining the pieces. The MacOS X native archiver doesn’t handle that, and I didn’t like the idea of installing an application just for this purpose, therefore I thought I’d resort to the Terminal console.

If you’re just a little adventurous, you can do splitting and concat-ting fairly easily, at absolutely no cost and without any need for specialised downloads. Start off with the split command. You can specify the size of each chunk with the -b option (use a lower case k for kilobytes or m for megabytes). Each file that your archive is split into will have a suffix of a number of letters that you can configure with -a. You then follow the command with the name of the file to pull apart 😉 and a prefix for the generated bits. Here’s an example

split -a 4 -b 2048m vwmaredisk.tar.gz vwmaredisk.tar.gz.

Note the dot at the end of the second file name, to separate the suffix that will be generated and appended automatically by the operation.

Given an initial archive of approximately 15Gb, the following files would be created by the preceding line

vwmaredisk.tar.gz.aaaa
vwmaredisk.tar.gz.aaab
vwmaredisk.tar.gz.aaac
vwmaredisk.tar.gz.aaad
vwmaredisk.tar.gz.aaae
vwmaredisk.tar.gz.aaaf
vwmaredisk.tar.gz.aaag
vwmaredisk.tar.gz.aaah

By default the prefix is ‘x’ and the suffix is made up of two letters, so that split -b 2048m vwmaredisk.tar.gz would create xaa, xab, xac, and so forth.

The various parts can be recombined to form the initial file with the cat command. For example

cat vwmaredisk.tar.gz.* > vwmaredisk.tar.gz

Just to be on the safe side and make sure that the order of the chunks is not for any reason mixed up, I would use a more complex but reliable construct

cat echo vwmaredisk.tar.gz.* | sort > vwmaredisk.tar.gz

Finally, just as a quick reminder mainly for myself: in order to compress a folder with the tar tool, this is the syntax to use

tar czvf vwmaredisk.tar.gz [-X excludes] [--exclude='pattern'] vwmaredisk/

where vmwaredisk is a folder to archive and the two optional -X and --exclude settings specify respectively (1) a file that contains a list of files (one per line) to exclude from the archive and (2) a pattern for files that will be excluded if matching.

Leave a comment

Your email address will not be published. Required fields are marked *


*