split

split breaks one file into several smaller files of roughly equal size.

split [options] [input [prefix]]
$ split -l 1000 big.log
$ ls
xaa  xab  xac  xad

By default split writes 1000 lines per piece, names the pieces xaa, xab, xac, … — a prefix of x followed by a two-letter suffix — and reads its input from a named file or from standard input.

To put the file back together, concatenate the pieces in order: cat xaa xab xac … > original.

Each piece is a newly created file, and a new file needs a security descriptor; each piece inherits one from the directory it is created in.

How big each piece is #

Choose one of these to set the piece size:

OptionEach piece holds…
-l, --lines=NN lines. This is the default behaviour, with N = 1000.
-b, --bytes=SIZESIZE bytes.
-C, --line-bytes=SIZEup to SIZE bytes, but only whole lines — never a line split across two pieces.
-n, --number=CHUNKSthe input divided into a fixed number of pieces (see below).

A SIZE accepts a unit suffix: K, M, G, … as powers of 1024, or KB, MB, … as powers of 1000.

Fixed number of chunks (-n) #

-n divides the input into a set number of pieces rather than fixing each piece's size. CHUNKS may be:

FormEffect
NSplit into N pieces by size.
l/NSplit into N pieces without splitting any line across pieces.
r/NLike l/N, but distribute lines round-robin across the pieces.
K/NWrite only the Kth of N pieces, to standard output.

Naming the pieces #

OptionEffect
prefix (operand)The leading part of each output name. Default x.
-a, --suffix-length=NUse N characters for the suffix. Default 2.
-d, --numeric-suffixes[=START]Use numeric suffixes (00, 01, …) instead of letters, optionally from START.
-x, --hex-suffixes[=START]Use hexadecimal suffixes.
--additional-suffix=SUFFIXAppend a fixed SUFFIX to every output name — for giving the pieces an extension.

Other options #

OptionEffect
-e, --elide-empty-filesWith -n, do not write out pieces that would be empty.
-t, --separator=SEPUse SEP as the line separator instead of newline.
--verbosePrint a line as each output file is opened.

Exit status #

CodeMeaning
0The file was split.
1A failure — the input could not be read, or the suffixes were exhausted.

Edit this page