This chapter is from the book
split
To break up a large file into a series of smaller files, use the split command. In the following example, the linux.words file is split into smaller files of 100,000 lines each. Each file is named x--, where “--” is aa, ab, ac, and so on.
[student@localhost dictionary]$ ls linux.words [student@localhost dictionary]$ split -l 100000 linux.words [student@localhost dictionary]$ ls linux.words xaa xab xac xad xae
Important options include the following:
Option | Description |
---|---|
-b | Break up files based on the number of bytes in each file (for example, split -b 5000 file.txt). |
-l | Break a file into smaller files based on the number of lines per file; the default is set to 1,000. |
To use a different prefix than “x”, add a second argument:
[student@localhost dictionary]$ ls linux.words [student@localhost dictionary]$ split -l 100000 linux.words words [student@localhost dictionary]$ ls linux.words wordsaa wordsab wordsac wordsad wordsae