Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

split - split a file into pieces

&pagelevel(4)&pagelevel

split divides a file into smaller segments, storing the segments in individual output files and leaving the original file unaltered.

The output files are automatically numbered; split uses a suffix comprising two lowercase letters (aa, ab ... zz) from the current internationalized environment for this purpose. The last file contains the remainder of the input file and may contain fewer lines than the number specified.

If the number of output files required exceeds the maximum length allowed by the suffix, split does not write the last file (as this would contain more lines than specified) and terminates with the exit status >0. The files that have already been created are not deleted.


Syntax


Format 1: split -b byte[ -a zahl][ datei[ name]]
Format 2: split[ -l zeilen][ -a zahl][ datei[ name]]
Format 3: split[ zeilen][ -a zahl][ datei[ name]]

No option specified

The output files are called xaa, xab etc. up to xzz in lexicographical sequence. In this case, split creates a maximum of 676 output files.



Format 1: split -b byte[ -a zahl][ datei[ name]]


-a number

The suffix for the output file consists of number letters. For example, -a 4 creates the output files xaaaa, xaaab etc. up to xzzzz.
Thus the maximum theoretically possible number of file names is 26number for 0<number<8. If number is greater than 7, it defaults to UINT_MAX.

-a not specified:
The suffix consists of 2 letters.

-b bytes

split splits the input file into sections of size bytes. bytes can be specified as follows:

nas the number of bytes
nk as a multiple of 1024 bytes
nm as a multiple of 1048576 bytes

file

Name of the input file you want to split.
If you use a dash (-) as the name for file, split reads from standard input.

file not specified:
split reads from standard input.

name

Name of the output files: The first output file is given the name name aa, the second receives the name name ab, and so on lexicographically, up to name zz.
So name must be at least 2 characters shorter (or number characters shorter if -a is specified) than the maximum file name length ({NAME_MAX} bytes) allowed in the file system.

If you specify a value for name, the file argument is mandatory.



Format 2: split[ -l zeilen][ -a zahl][ datei[ name]]
Format 3: split[ zeilen][ -a zahl][ datei[ name]]

-l lines

split splits the input file into sections containing lines lines. This corresponds to the old option lines, which is still supported.

-l not specified:
split splits the input file into sections containing 1000 lines.

-a number

The suffix for the output file consists of number letters. For example, -a 4 creates the output files xaaaa, xaaab etc. up to xzzzz.
Thus the maximum theoretically possible number of file names is 26number for 0<number<8. If number is greater than 7, it defaults to UINT_MAX.

-a not specified:
The suffix consists of 2 letters.

file

Name of the input file you want to split.

If you use a dash (-) as the name for file, split reads from standard input.

file not specified:
split reads from standard input.

name

Name of the output files: The first output file is given the name name aa, the second receives the name name ab, and so on lexicographically, up to name zz.
So name must be at least 2 characters shorter (or number characters shorter if -a is specified) than the maximum file name length ({NAME_MAX} bytes) allowed in the file system.

If you specify a value for name, the file argument is mandatory.

Locale

The following environment variables affect the execution of split:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

The contents of the file example are to be split into several 20-line files:

$ split -l 20 example
$ ls

example

xaa

xab

xac

xad

Example 2

Every two lines from the standard input are to be written into files named out... Since the names of output files are explicitly specified (out) in this case, the minus sign (-) for standard input must not be omitted!

$ split -l 2 - out

What is true was always true

and will always remain true.

But what is not true, was never reality

and will never become reality.

CRTL+D

$ ls

outaa

outab

See also

csplit