Split Large tar into Multiple Files of Certain Size
In this article
Yes, you can split a large tar archive into multiple files of a specific size using the split command in combination with tar. The standard approach is to create a tar archive and pipe it through split, which divides the data into chunks of a chosen size (e.g., 100M, 1G). To restore the original archive, you simply concatenate the parts with cat before extracting.
Background: Why Split a tar Archive?
Tar (Tape Archive) is a Unix-based file archiving format that bundles multiple files into a single stream. It is widely used for backups, software distribution, and transferring large directory trees. However, a single tar file can become unwieldy when it exceeds the size limits of a target filesystem, a USB drive formatted as FAT32 (which has a 4 GB per-file limit), or an email attachment service. Splitting a tar into smaller parts allows you to store or transfer the archive across multiple media or channels, and then reassemble it on the destination.
How to Split a tar Archive with split
The most common method uses a pipeline between tar and split. Here is the basic command structure:
tar -cvf - /path/to/directory | split -b 100M - archive.tar.part_This command does the following:
tar -cvf -creates a tar archive from the specified directory and writes it to standard output (-instead of a filename).split -b 100Mreads standard input and splits it into chunks of 100 megabytes each.- archive.tar.part_tells split to name the output files using the prefixarchive.tar.part_followed by two-letter suffixes (aa, ab, ac, etc.).
You can adjust the chunk size using suffixes like K (kilobytes), M (megabytes), G (gigabytes), or b (512-byte blocks). For example, -b 1G creates 1 GB parts.
How to Reassemble and Extract the Split Archive
To restore the original tar file, concatenate the parts using cat and pipe the result to tar for extraction:
cat archive.tar.part_* | tar -xvf -If you want to first recreate a single tar file (for example, to verify its integrity or keep it as a backup), you can do:
cat archive.tar.part_* > archive.tarThen extract normally with tar -xvf archive.tar. The wildcard * expands to all parts in alphabetical order, which is correct because split names them sequentially (aa, ab, ac, ...).
Choosing the Right Chunk Size
The optimal chunk size depends on your storage medium and transfer method. Consider these factors:
- Filesystem limits: FAT32 has a 4 GB per-file maximum, so choose a size below that (e.g., 3.5 GB) if you are copying to a USB stick formatted that way.
- Cloud upload limits: Some services impose a per-file upload cap (often 5 GB or 10 GB). Check the service’s documentation and choose a size accordingly.
- Optical media: If you plan to burn to DVDs, use 4.7 GB (or 4.3 GB for writable DVDs) to fit the disc.
- Network transfer reliability: Smaller chunks (e.g., 100 MB) are easier to resume if a transfer drops mid-way, but they create more files and more overhead.
A practical approach is to first check the total size of the tar archive with du -h archive.tar or ls -lh, then divide by the number of parts you want. For example, a 10 GB archive split into 5 parts would use -b 2G.
Common Problems and Misconceptions
One frequent mistake is using tar -cvf archive.tar /path and then trying to split the resulting file with split -b 100M archive.tar. This works, but it requires the tar file to be fully created first, which can be slow for huge directories. The pipeline method avoids the intermediate file and is more efficient.
Another misconception is that you can extract directly from the split parts without concatenating. This is not possible with standard tar; you must reassemble the archive first. Some tools like 7z can create split archives natively, but for tar, the split/cat method is the standard.
Also, be aware that split does not compress data. If you want compression, you can add z (gzip) or j (bzip2) to the tar command, but then the split parts are compressed chunks of the compressed stream. For example:
tar -czvf - /path | split -b 100M - archive.tar.gz.part_To reassemble, use cat archive.tar.gz.part_* | tar -xzvf -.
Alternatives to split and cat
While split is the classic Unix tool, there are other ways to achieve the same result:
- tar with multi-volume support: The
tarcommand itself has a--multi-volumeoption (-M) that prompts you to insert a new volume when the current one is full. However, it is interactive and less suitable for scripting. - 7-Zip: On Windows and Linux,
7zcan create split archives with the-vflag (e.g.,7z a -v100m archive.7z /path). It also compresses, which can reduce total size. - ZIP with split: Some ZIP tools support splitting, but the resulting files are not standard ZIP files and may require the same tool to reassemble.
For most Unix-like systems, the split/cat method is preferred because it uses only standard tools that are always available.
Safety and Integrity Checks
Before deleting the original archive or directory, verify that the split parts are intact. After reassembling, you can check the tar archive’s integrity with:
tar -tvf archive.tarThis lists the contents without extracting. You can also compare the checksum of the reassembled file with the original using md5sum or sha256sum. If you created the tar file on the fly, you won’t have a checksum for the original, but you can compute one after reassembly and store it for future verification.
Frequently Asked Questions
Can I split an existing tar file without re-archiving?
Yes, simply run split -b 100M archive.tar part_. This splits the existing file into parts. To reassemble, use cat part_* > archive.tar.
What is the maximum size for a split part on FAT32?
FAT32 has a maximum file size of 4 GB (actually 4,294,967,295 bytes). To be safe, use a chunk size like 3.5 GB (-b 3500M) or smaller.
Do I need to compress the tar before splitting?
No, compression is optional. If you want to save space, use tar -czvf - (gzip) or tar -cjvf - (bzip2). Keep in mind that compressed archives are less resilient to corruption; a single damaged byte can make the whole archive unreadable.
Can I extract directly from the split parts without concatenating?
No, standard tar cannot read from multiple files directly. You must concatenate the parts first. Some archive managers (like 7-Zip) can open split tar parts if they are named with a specific pattern, but the command-line tar does not.
What happens if I lose one of the split parts?
Without that part, you cannot reassemble the archive, and the entire archive is effectively lost. This is why it’s important to store all parts together and verify them after transfer.