GNU Split: Examples and Reference

GNU Split: Examples and Reference

Last updated:
Table of Contents

Split is a very useful tool included in most Linux distributions. It can be used to split large files into smaller parts according to a variety of parameters:

Basic example

Default behaviour is to split file into parts containing 1000 lines

$ split largefile.txt

Split file into chunks by number of lines

For example, have each part have 1 thousand lines:

$ split -l 1000 largefile.txt

Split file into chunks by size (in bytes)

Each chunk will have at most the given size (the last chunk may be smaller).

For example, 10MB

$ split largefile.txt -b 10MB

Split file into N equal-sized chunks

(Each chunk will have totalSize / N size)

For example, divide a large file into 10 parts

This may split files halfway through a line

$ split largefile.txt -n 10

Split files into N equal-sized chunks without splitting lines

Use l/N where N is the number of parts you want. This will only split files at line endings.

For example, divide a large file into 10 parts, each having 1/10 of the lines:

$ split largefile.txt -n l/10

Rebuild a file from its parts

File parts start with x so use cat ./x* > rebuilt_file

$ split largefile.txt
$ ls
xaa xab xac
$ cat ./x* > rebuiltfile.txt

See also