Home·Terminal commands

split

Text processing

Usage

split -l 1000 [file] [prefix]

Cuts a file into pieces; a header row stays only in the first piece, and the names end in aa, ab unless you pass -d for numbers.

Common flags

FlagMeaning
-lHow many lines per output file
-bHow many bytes per file, with suffixes such as 50M
-nCut into this many roughly equal pieces
-dNumber the pieces instead of naming them aa, ab
-aHow many characters the suffix has
--additional-suffixGNU: give every piece an extension

Examples

split -l 1000 big.csv part_

Files part_aa, part_ab, 1000 lines each.

split -b 50M archive.tar chunk_

Pieces of 50 MB.

cat chunk_* > archive.tar

Puts the pieces back together.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does split do?

Cuts a file into pieces; a header row stays only in the first piece, and the names end in aa, ab unless you pass -d for numbers.

Q. How do I type it?

split -l 1000 [file] [prefix] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man split. This command sits under Text processing.

Related commands

man page: man split