my-server
← Wiki

Split (Unix)

<code>split</code> is a utility on Unix, Plan 9, and Unix-like operating systems most commonly used to split a computer file into two or more smaller files.

History

The command first appeared in Version 3 Unix and is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. The version of <code>split</code> bundled in GNU coreutils was written by Torbjorn Granlund and Richard Stallman. The command has also been ported to the IBM i operating system.

Usage

The command-syntax is:

The default behavior of <code>split</code> is to generate output files of a fixed size, default 1000 lines. The files are named by appending aa, ab, ac, etc. to output filename. If output filename is not given, the default filename of x is used, for example, xaa, xab, etc. When a hyphen (-) is used instead of input filename, data is derived from standard input. The files are typically rejoined using a utility such as cat.

Additional program options permit a maximum character count (instead of a line count), a maximum line length, how many incrementing characters in generated filenames, and whether to use letters or digits.

Split file into pieces

Create a file named "<code>myfile.txt</code>" with exactly 3,000 lines of data:

Now, use the <code>split</code> command to break this file into pieces (note: unless otherwise specified, <code>split</code> will break the file into 1,000-line files):

As seen above, the <code>split</code> command has broken the original file (keeping the original intact) into three, equal in number of lines (i.e., 1,000), files: <code>xaa</code>, <code>xab</code>, and <code>xac</code>.

See also

References

External links