LinuxCommandLibrary

split

TLDR

Split file into 1000-line pieces

$ split [file]
copy
Split into pieces with custom prefix
$ split [file] [prefix_]
copy
Split into specific number of lines
$ split -l [500] [file]
copy
Split into specific size pieces
$ split -b [10M] [file]
copy
Split into N equal pieces
$ split -n [5] [file]
copy
Split with numeric suffixes
$ split -d [file]
copy
Split with custom suffix length
$ split -a [4] [file]
copy

SYNOPSIS

split [options] [file [prefix]]

DESCRIPTION

split divides a file into smaller pieces. By default, it creates files with 1000 lines each, named with a prefix (default: x) followed by a suffix (aa, ab, ac, ...).
The command is useful for breaking large files for transmission, processing, or storage limitations. It works with both text and binary files.
Size specifications accept suffixes: K (kilobytes), M (megabytes), G (gigabytes), and also KB, MB, GB for powers of 1000.
Split reads from stdin if no file is specified or if file is -.

PARAMETERS

-l lines, --lines=lines

Put specified number of lines per output file
-b size, --bytes=size
Put specified bytes per output file (K, M, G suffixes)
-n chunks, --number=chunks
Generate specified number of output files
-d, --numeric-suffixes
Use numeric suffixes instead of alphabetic
-a N, --suffix-length=N
Generate suffixes of length N (default: 2)
-e, --elide-empty-files
Do not generate empty output files with -n
--verbose
Print message for each output file
--additional-suffix=suf
Append additional suffix to file names
-x, --hex-suffixes
Use hexadecimal suffixes

CAVEATS

The default 2-character suffix limits output to 676 files (aa-zz). Use -a to increase suffix length for more pieces, or -d for numeric suffixes.
When splitting binary files, use -b (bytes) not -l (lines) to avoid corruption at arbitrary byte boundaries.
To reassemble, use cat prefix\* > original_file. Ensure files are concatenated in correct alphabetical/numerical order.

SEE ALSO

csplit(1), cat(1), head(1), tail(1)

Copied to clipboard