Commands.page Logo

How to Create Split Compressed Tar Archives on Ubuntu

This article details the process of creating split compressed archives using tar on Ubuntu. It outlines the commands required to compress data, divide it into smaller chunks, and reassemble the files for extraction. This method is particularly useful for backing up large directories to filesystems with file size limits or transferring data over networks with attachment restrictions.

Prerequisites

You need a standard Ubuntu installation with terminal access. The tar and split utilities are pre-installed on all Ubuntu systems, so no additional software installation is required. Open your terminal application to begin.

Create and Split the Archive

The most efficient method is to compress the data and split it simultaneously using a pipe. This avoids creating a massive intermediate file. Run the following command in your terminal:

tar -czf - /path/to/your/directory | split -b 500M - archive.tar.gz.

In this command: * tar -czf - creates a compressed gzip archive and outputs it to standard output instead of a file. * /path/to/your/directory is the folder you want to archive. * split -b 500M divides the incoming data into 500 megabyte chunks. * archive.tar.gz. is the prefix for the split files.

The resulting files will be named archive.tar.gz.aa, archive.tar.gz.ab, archive.tar.gz.ac, and so on. You can adjust the 500M value to 1G for gigabytes or 100M for smaller segments depending on your needs.

Reassemble and Extract the Archive

To restore the data, you must first combine the split parts back into a single stream and then extract them. Navigate to the directory containing the split files and run:

cat archive.tar.gz.* | tar -xz

This command works as follows: * cat archive.tar.gz.* concatenates all the split parts in the correct alphabetical order. * The pipe | sends the combined data directly to tar. * tar -xz decompresses and extracts the contents to the current directory.

Verify the Integrity

After extraction, check the restored files to ensure no data corruption occurred during the splitting or transfer process. Compare the file sizes or use checksums like sha256sum on the original and extracted directories if verification is critical for your workflow.