split
Split a file into smaller pieces
By CMD Script Team · 4 min read · Last updated
split [OPTIONS] [FILE [PREFIX]]Options
| Flag | Description |
|---|---|
-l | Split by number of lines per output file (default is 1000) |
-b | Split by size per output file, e.g. -b 10M or -b 500k |
-d | Use numeric suffixes (00, 01, 02...) instead of the default alphabetic ones |
-a | Set the suffix length, e.g. -a 4 for four-character suffixes |
--additional-suffix | Append a fixed suffix (like a file extension) to every output file name |
-n | Split into a specific number of output files, e.g. -n 4 |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (BSD split, no -n or --additional-suffix)
What it does
split breaks a single file into a series of smaller output files, either by a fixed
number of lines (-l) or a fixed byte size (-b), without altering the content itself.
Output files are named with a prefix (default x) followed by a suffix, alphabetic by
default (xaa, xab, xac, ...) or numeric with -d. It's the standard tool for
breaking up large logs or files that exceed a transfer or storage size limit.
Beginner examples
split file.txt— split into 1000-line chunks namedxaa,xab, ...split -l 500 file.txt— split into 500-line chunkssplit -b 10M bigfile.iso— split into 10MB chunkssplit -l 200 access.log part_— split with a custom filename prefix
split -l 100000 huge_export.csv chunk_
Advanced examples
- Split a large archive into fixed-size pieces for upload to a size-limited service:
split -b 25M backup.tar.gz backup_part_ - Use numeric instead of alphabetic suffixes for easier scripting:
split -d -a 3 -l 10000 data.csv part_ - Split into a specific number of roughly equal pieces (GNU split):
split -n 4 dataset.csv part_ - Reassemble pieces in the correct order:
cat part_* > dataset_restored.csv - Split while adding a matching file extension to each piece (GNU split):
split -b 5M --additional-suffix=.part video.mp4 chunk_
split -d -b 50M dump.sql sqlpart_ && ls sqlpart_*
Common mistakes
- Assuming
splitcompresses or otherwise transforms the data — it doesn't; it purely divides bytes or lines, so total size stays the same (plus tiny per-file overhead). - Losing track of piece order when using a glob to reassemble (
cat part_*) if the default alphabetic suffixes run pastz— always verify with-dand zero-padded numbers for anything beyond 26 pieces, or increase-a. - Splitting a CSV or log file by raw byte count (
-b) and cutting a line in half midway through a piece — use-lwhen line integrity matters. - Forgetting to specify a prefix, leaving pieces named
xaa,xab, etc., which can be confusing when multiple split jobs run in the same directory.
Tips
- Use
-dwith an explicit-a(suffix length) so pieces sort correctly and predictably once you get past 26 or 676 files. - Preview how many pieces you'll get before running the real split:
wc -l file.txtdivided by your-lvalue gives an estimate. - For binary files (backups, ISOs, media), always use
-b, not-l, since line-based splitting only makes sense for text.
Best practices
- Always verify reassembly with a checksum:
sha256sum original.filebefore splitting andcat part_* | sha256sumafter, to confirm no bytes were lost or reordered. - Choose a descriptive prefix and, on GNU split,
-d/--additional-suffixso piece filenames are self-explanatory instead of the cryptic defaultxaa/xab. - Prefer
-lfor text files you might need to inspect or grep piece-by-piece, and-bfor anything that will only ever be reassembled whole.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Breaking a multi-gigabyte database dump into upload-friendly chunks:
split -b 100M dump.sql dump_part_. - Splitting a huge CSV export for parallel processing across multiple worker scripts:
split -l 50000 export.csv worker_input_. - Chunking a large log file to email a support team when direct upload isn't possible:
split -b 10M -d incident.log log_part_.
Common interview questions
- What's the difference between
-land-binsplit?-lsplits by a fixed number of lines, keeping line boundaries intact;-bsplits by raw byte size, which can cut a line in the middle. - How do you reassemble files created by
split? Concatenate the pieces in order:cat xaa xab xac > original(orcat prefix* > originalif the naming sorts correctly). - Why might you use
-dinstead of the default suffixes?-dproduces numeric suffixes (00,01,02...) which sort predictably and scale past 26 pieces, unlike the default alphabetic suffixes which wrap awkwardly.
Frequently Asked Questions
How do I split a file into equal-sized chunks by line count?
Use split -l 1000 file.txt, which creates files of 1000 lines each named xaa, xab, xac, and so on.
How do I put the pieces back together?
Since split doesn't alter content, concatenating the pieces in order recreates the original: cat xaa xab xac > original.txt, or simply cat x* > original.txt if the alphabetic ordering matches.
Why would I split by bytes instead of lines?
When uploading to a service with a file-size limit (like email attachments or removable media), -b lets you cap each piece at an exact size, e.g. split -b 25M archive.tar.gz part_ regardless of line structure — useful for binary files that have no meaningful line boundaries.
How do I get numbered suffixes like part_001, part_002 instead of xaa, xab?
Combine -d for numeric suffixes with a custom prefix and --additional-suffix if needed: split -d -a 3 -l 1000 file.txt part_ produces part_000, part_001, and so on.
Cheat sheet
Download a quick-reference cheat sheet for split.