How to Split Large Files into Smaller Chunks in Ubuntu
Managing large files on Ubuntu can be challenging when transferring or storing data. This article explains how to use the built-in split command to divide large files into manageable chunks of a specific size. You will learn the basic syntax, common examples, and how to reassemble the original file after splitting.
The Split Command
The primary command for dividing files in Ubuntu is
split. It is pre-installed on most Linux distributions.
This tool reads a file and writes it in fixed-size chunks to one or more
output files.
Basic Syntax
The general structure for the command is:
split [OPTION]... [INPUT [PREFIX]]To split a file by size, use the -b flag followed by the
desired size.
Splitting by Specific Size
To split a large file into 100 megabyte chunks, run the following command:
split -b 100M largefile.zip part_This creates files named part_aa, part_ab,
part_ac, and so on. You can customize the prefix
part_ to any name you prefer.
Common Size Units
When specifying size, you can use the following suffixes:
bfor 512-byte blocksKfor kilobytesMfor megabytesGfor gigabytes
For example, to split a video file into 1 gigabyte parts:
split -b 1G video.mp4 video_chunk_Reassembling the File
To restore the original file from the chunks, use the
cat command. Ensure you are in the directory containing the
split parts and run:
cat part_* > largefile.zipReplace part_* with the prefix you used during
splitting. This command concatenates all parts in alphabetical order
back into the single original file.
Verifying the Output
After reassembling, it is good practice to verify the file integrity.
You can compare the checksum of the new file against the original if you
saved it beforehand. Use the md5sum command to generate a
hash for verification.
md5sum largefile.zipThis ensures that no data was lost or corrupted during the splitting and merging process.