Categories
Geeky

Splitting tar archives on the fly

Taken from RedHat Magazine. This code is very useful, if you try to build a tar archive, which exceeds the maximum file size (SMB for example still is at 2GB).

First create the archive:
tar -czf /dev/stdout $(DIRECTORY_OR_FILE_TO_COMPRESS) | split -d -b $(CHUNK_SIZE_IN_BYTES) - $(FILE_NAME_PREFIX)

To extract the contents:
cat $(FILE_NAME_PREFIX)* >> /dev/stdout | tar -xzf /dev/stdin

The above shown set of commands works on the fly. You don’t need additional free space for temporary files.