Linux Command Reference ยท Viewing and Searching Files
Linux split command
Reference for the Linux split command: cut a file into pieces by lines, bytes or count, name the pieces, use numeric suffixes and join them back with cat.
split cuts one file into several smaller files. You choose the size of the pieces by lines (-l), by bytes (-b), or ask for a fixed number of pieces (-n). The pieces are named with a prefix and a suffix that sorts in order (xaa, xab, ...), so the shell glob x* lists them in the right sequence and cat x* puts them back together.
Typical uses are breaking a huge log into manageable chunks, fitting a large archive onto size-limited storage, and spreading lines of work across several parallel processes.
split [OPTION]... [FILE [PREFIX]]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
split [-l LINES | -b SIZE | -C SIZE | -n CHUNKS] [-d | -x] [-a LEN] [FILE [PREFIX]]
FILE defaults to standard input (also -). PREFIX defaults to x.
| Option | Description |
|---|---|
-l N |
N lines per piece (default 1000). |
-b SIZE |
SIZE bytes per piece; suffixes K, M, G are powers of 1024, KB, MB powers of 1000. |
-C SIZE |
At most SIZE bytes per piece, but never break a line. |
-n N |
Exactly N pieces by size. -n l/N splits by lines without cutting one; -n K/N prints only piece K. |
-d |
Numeric suffixes (00, 01, ...) instead of letters. |
-x |
Hexadecimal suffixes. |
-a LEN |
Suffix length (default 2). |
--additional-suffix=S |
Append S to every name, such as .txt. |
-e |
With -n, do not create empty pieces. |
-t SEP |
Use SEP instead of newline as record separator. |
--filter=CMD |
Pipe each piece through CMD (with $FILE set to the would-be name) instead of writing a file. |
-u |
Do not buffer output. |
--verbose |
Print a line as each piece is created. |
Errors: split stops with output file suffixes exhausted when there are more pieces than the suffix length allows (with -a 2 letters give 676 pieces). Use a longer suffix with -a.
Usage notes
- Order of names. Suffixes sort alphabetically in creation order, so
cat prefix*rebuilds the file. With-dand a fixed length the same holds; do not mix different suffix lengths. - Lines vs. bytes.
-bcan cut in the middle of a line or even a multi-byte character. For text use-lor-C. - Existing files are overwritten without warning when their names match a new piece. Choose a distinct prefix.
- Verifying a split. Compare the joined result with the original using
cmpor a checksum fromsha256sum. - Splitting a stream.
tar cf - dir | split -b 100M - backup.tar.creates 100 MB pieces without ever writing the whole archive to disk. - Different tool for different goals. To split on content (for example at every line that starts a new section) use
csplit. To cut columns, usecut. - Empty input produces no output files.