# Split (Unix)

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Split_(Unix)
> Markdown URL: https://mediated.wiki/source/Split_(Unix).md
> Source: https://en.wikipedia.org/wiki/Split_(Unix)
> Source revision: 1341095852
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|UNIX text-processing utility program}}
{{lowercase title}}
{{Infobox software
| name                   = split
| logo                   = 
| screenshot             = Split-example.png
| screenshot size        = 
| caption                = Example of <code>split</code> usage
| author                 = [AT&T Bell Laboratories](/source/AT%26T_Bell_Laboratories)
| developer              = Various [open-source](/source/open-source_software) and [commercial](/source/commercial_software) developers
| released               = {{Start date and age|1973|2}}
| latest release version = 
| latest release date    = 
| programming language   = [C](/source/C_(programming_language))
| operating system       = [Unix](/source/Unix), [Unix-like](/source/Unix-like), [Plan 9](/source/Plan_9_from_Bell_Labs), [IBM i](/source/IBM_i)
| platform               = [Cross-platform](/source/Cross-platform)
| genre                  = [Command](/source/Command_(computing))
| license                = [coreutils](/source/coreutils): [GPLv3+](/source/GPLv3%2B)<br />Plan 9: [MIT License](/source/MIT_License)
| website                = 
}}
'''<code>split</code>''' is a utility on [Unix](/source/Unix), [Plan 9](/source/Plan_9_from_Bell_Labs), and [Unix-like](/source/Unix-like) [operating system](/source/operating_system)s most commonly used to split a [computer file](/source/computer_file) into two or more smaller files.

==History==
The {{code|split}} [command](/source/command_(computing)) first appeared in [Version 3 Unix](/source/Ancient_Unix)<ref>{{man|1|split|FreeBSD}}</ref> and is part of the [X/Open](/source/X%2FOpen) Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the [Single Unix Specification](/source/Single_Unix_Specification).<ref>{{man|cu|split|SUS}}</ref> The version of <code>split</code> bundled in [GNU coreutils](/source/GNU_coreutils) was written by Torbjorn Granlund and [Richard Stallman](/source/Richard_Stallman).<ref>{{Cite web|url=https://linux.die.net/man/1/split|title=split(1): split file into pieces - Linux man page|website=linux.die.net|access-date=2019-01-24|archive-date=2018-09-24|archive-url=https://web.archive.org/web/20180924110847/https://linux.die.net/man/1/split|url-status=live}}</ref> The {{Mono|split}} command has also been ported to the [IBM i](/source/IBM_i) operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[IBM](/source/IBM) |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 |archive-date=2020-09-18 |archive-url=https://web.archive.org/web/20200918130823/https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |url-status=live }}</ref>

==Usage==
The command-[syntax](/source/syntax) is:
<syntaxhighlight lang="bash">
 split [OPTION] [INPUT [PREFIX]]
</syntaxhighlight>

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](/source/standard_input). The files are typically rejoined using a utility such as [cat](/source/cat_(Unix)).

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:
<syntaxhighlight lang="console">
$ head -3000 < /dev/urandom > myfile.txt
</syntaxhighlight>

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):
<syntaxhighlight lang="console">
$ split myfile.txt
$ ls -l
-rw-r--r--  1 root root 761K Jun 16 18:17 myfile.txt
-rw-r--r--  1 root root 242K Jun 16 18:17 xaa
-rw-r--r--  1 root root 263K Jun 16 18:17 xab
-rw-r--r--  1 root root 256K Jun 16 18:17 xac
$ wc --lines xa*
  1000 xaa
  1000 xab
  1000 xac
  3000 total
</syntaxhighlight>
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==
* [csplit](/source/csplit) – splits by content rather than by size
* [File spanning](/source/File_spanning)
* [List of Unix commands](/source/List_of_Unix_commands)

==References==
{{Reflist}}

==External links==
{{Wikibooks|Guide to Unix|Commands}}
*{{man|cu|split|SUS}}

{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}

Category:Standard Unix programs
Category:Unix SUS2008 utilities
Category:Plan 9 commands
Category:IBM i Qshell commands

{{unix-stub}}

---
Adapted from the Wikipedia article [Split (Unix)](https://en.wikipedia.org/wiki/Split_(Unix)) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Split_(Unix)?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
