Skip to content
Latchkey

split -l: Split a File by Line Count

split -l divides a file into pieces of N lines each, named with a prefix and a suffix.

split chops a big input into smaller files, useful for batching work or parallelizing across runners.

What it does

split -l N writes consecutive groups of N lines to output files named PREFIXaa, PREFIXab, and so on (default prefix x). -a sets the suffix length, -d uses numeric suffixes, and --additional-suffix adds an extension. The final chunk holds the remainder.

Common usage

Terminal
split -l 1000 big.txt chunk_           # chunk_aa, chunk_ab, ...
split -l 1000 -d big.txt part_         # part_00, part_01, ...
split -l 500 --additional-suffix=.txt big.txt out_
split -l 100 - prefix_ < stream        # split a stream

Options

FlagWhat it does
-l NLines per output file
-a NSuffix length (default 2)
-dUse numeric suffixes instead of letters
--additional-suffix=<s>Append an extension to each piece
--numeric-suffixes=NNumeric suffixes starting at N

In CI

split -l shards a list of test files or work items into N-line batches, one per parallel job. Use -d for numeric suffixes that map cleanly to a matrix index, and -a to widen the suffix when you expect more than 26 (or 100) chunks.

Common errors in CI

With the default 2-character suffix, more than 676 letter chunks (or 100 numeric) exhausts the suffix space and split errors "output file suffixes exhausted"; raise -a. The default prefix is x, so split with no prefix writes xaa, xab into the current directory unexpectedly; always pass a prefix. --additional-suffix and --numeric-suffixes are GNU; BSD/macOS split lacks them.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →