Working with multi-gigabyte server logs, extensive database dumps, or raw disk images in Linux frequently presents logistical bottlenecks. Massive files often exceed email attachment thresholds, fail during fragile network file transfers, or prove too large to open inside standard text editors. While archiving tools like tar can bundle directories, breaking a single massive file into uniform, manageable pieces requires a dedicated tool.
The GNU split command is a core utility included by default on every Linux distribution. It rapidly partitions files of any size into smaller chunks based on line counts, byte sizes, or chunk numbers—without altering the underlying binary data. Furthermore, reconstructing the original file requires nothing more than the standard cat command. In this guide, we explore how to split files by size and lines, configure numeric and custom file extensions, and verify reconstructed files.
In This Guide
- Basic Syntax of the split Command
- Splitting Files by Exact Byte or Megabyte Size (-b Option)
- Splitting Text Files by Line Count (-l Option)
- Using Numeric Suffixes Instead of Letters (-d Option)
- Adding Custom Prefixes and File Extensions
- Reassembling Split Chunks Back into the Original File
- Verifying File Integrity Using Checksums
Basic Syntax of the split Command
The standard syntax for the split command is:
split [options] [input_file] [output_prefix]
When run without optional flags, split defaults to cutting text files into chunks of 1,000 lines each. By default, it generates output files using the prefix x followed by alphabetical suffixes: xaa, xab, xac, and so on.
split large_access.log
While alphabetical suffixes work, adding descriptive prefixes, numeric increments, and specific file extensions creates much cleaner, self-explanatory chunks.
Splitting Files by Exact Byte or Megabyte Size (-b Option)
When partitioning binary files, video media, ISO images, or compressed archives for transfer across cloud services or FAT32 USB drives (which cannot store single files over 4 GB), splitting by byte size is the ideal approach.
Use the -b flag followed by an integer and a size multiplier unit (such as K, M, or G):
To split a large database backup into 500-megabyte parts:
split -b 500M database_backup.sql.gz backup_part_
To split a massive disk image into 2-gigabyte segments:
split -b 2G virtual_disk.raw vdisk_chunk_
The command will generate files named backup_part_aa, backup_part_ab, etc., each exactly 500 MB in size (with the final chunk containing whatever remainder data is left).
Splitting Text Files by Line Count (-l Option)
If you are processing enormous CSV spreadsheets, SQL imports, or application logs, dividing the data by lines ensures that records are not chopped in half mid-sentence.
Use the -l (or --lines) flag followed by the maximum number of lines allowed per chunk:
split -l 50000 customer_records.csv chunk_
Each resulting output file will contain exactly 50,000 complete lines, making parallel data processing with Python scripts or distributed workers significantly easier.
Using Numeric Suffixes Instead of Letters (-d Option)
Alphabetical suffixes (xaa, xab) can be unintuitive when sorting in directory listings. Adding the -d (or --numeric-suffixes) flag instructs split to use zero-padded decimal numbers instead (00, 01, 02):
split -b 100M -d server.iso iso_part_
This generates files named: iso_part_00, iso_part_01, iso_part_02.
By default, -d uses a suffix length of two digits. If you anticipate creating more than 100 pieces (which would exhaust two digits), define custom suffix padding with -a:
split -b 100M -d -a 4 large_archive.tar archive_split_
The pieces will be numbered with four digits: archive_split_0000, archive_split_0001, and so on.
Adding Custom Prefixes and File Extensions
When splitting specific file types like CSVs or compressed archives, having the resulting chunks retain their proper file extension is essential for third-party scripts. Use the --additional-suffix flag to append an extension cleanly:
split -l 10000 -d --additional-suffix=.csv transactions.csv batch_
This command produces output files formatted as batch_00.csv, batch_01.csv, and batch_02.csv, preserving automatic file associations.
Reassembling Split Chunks Back into the Original File
Recombining split pieces on any Linux machine is remarkably simple. Because split slices files sequentially at exact byte boundaries, concatenating the chunks using the cat utility with a wildcard reconstructs the original file byte-for-byte:
cat iso_part_* > restored_server.iso
Or for custom-named chunks:
cat backup_part_* > restored_backup.sql.gz
Ensure that your shell wildcard expands the pieces in their exact numerical or alphabetical order. Using numeric zero-padding (-d) guarantees that shell globbing matches the chunks in correct sequence.
Verifying File Integrity Using Checksums
Whenever you split, transfer, and reconstruct files across networks or storage volumes, verifying that not a single byte was corrupted is a recommended best practice.
- Before splitting the source file, calculate its SHA-256 hash:
(Record the resulting 64-character hash string.)sha256sum original_file.tar.gz - After transferring and reconstructing the pieces with
caton the destination machine, compute the hash of the restored file:sha256sum restored_file.tar.gz - Compare the two hash strings. If they match identically, your reconstructed file is 100% integral and undamaged.