Split File Into Smaller Parts in Linux

Split File Into Smaller Parts in Linux

Most of file hosting services has file size limitations for uploading files. Before uploading file, it can be splitted into smaller parts. This tutorial shows how to do that in Linux.

For demonstration purpose, create a simple text file:

printf "Line1\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9\n" > test.txt

The split command can be used for splitting files into smaller parts. In order to split file by line number count, use the -l option. For example, the following command splits the file into 4 lines per file:

split -l 4 test.txt

In our case, 3 files was created named xaa, xab and xac.

Prefix for new files can be specified as second argument:

split -l 4 test.txt test.txt_

In such case, command will create files named test.txt_aa, test.txt_ab and test.txt_ac.

File can be splitted by size as well. It can be done using -b option. For example, the following command splits the file into 40 bytes per file:

split -b 40 test.txt test.txt_

In such case, files named test.txt_aa and test.txt_ab will be created.

Note that, file size can be specified together with unit (e.g. 40K = 40 bytes * 1024). Units are K, M, G, T, P, E, Z, Y.

Splitted files can be combined using cat command as follows:

cat test.txt_* > new_test.txt

Leave a Comment

Cancel reply

Your email address will not be published.