Skip to content

split Command Cheat Sheet

split breaks a file into smaller pieces. This is useful for emailing large files, backing up to smaller media, or parallel processing logs.


Synopsis

split [OPTION]... [FILE [PREFIX]]

Basic Usage

Default: Splits into 1000-line chunks named xaa, xab, xac...

split large_file.txt

Custom Prefix

Start output names with log_part_.

split large_file.txt log_part_

Split Method

By Number of Lines (-l)

Split every 500 lines.

split -l 500 file.txt

By File Size (-b)

Split into 10MB chunks.

split -b 10M video.mp4 part_
(Supported units: K, M, G, T).

By Line Bytes (-C)

Split as much as possible up to SIZE bytes per file, but enforce line boundaries (don't cut a line in half).

split -C 1M logs.txt

By Number of Files (-n)

Split into exactly 5 files of equal size.

split -n 5 data.csv

Naming Options

Numeric Suffixes (-d)

Use x00, x01 instead of xaa, xab.

split -d large_file.txt

Additional Suffix Length (-a)

Example: If you expect more than 100 parts, you need 3 digits (x000 to x999).

split -d -a 3 large_file.txt

Recombining Files

Use cat to put them back together.

cat x* > restored_file.txt

Verify integrity:

md5sum large_file.txt restored_file.txt


Filter Mode

Split output of a command directly.

grep "Error" huge.log | split -l 100 - error_part_
(- denotes Stdin).


Notes

  • Data Loss: split -b (binary split) does not lose data, but if you split a text file mid-line, the pieces might not be individually readable text files. Use -C for text.