How to split files by size and merge them

Lets say that we have one big file and want to split it into 10M parts.

$ ls -lh
razem 44M
-rw-r----- 1 milosz milosz 44M 2011-02-27 16:28 file.png

To divide file into smaller parts we will use split command.

$ split -d -b10M file.png file1.part
$ ls -lh
razem 87M
-rw-r--r-- 1 milosz milosz  10M 2011-02-27 16:39 file1.part00
-rw-r--r-- 1 milosz milosz  10M 2011-02-27 16:39 file1.part01
-rw-r--r-- 1 milosz milosz  10M 2011-02-27 16:39 file1.part02
-rw-r--r-- 1 milosz milosz  10M 2011-02-27 16:39 file1.part03
-rw-r--r-- 1 milosz milosz 3,3M 2011-02-27 16:39 file1.part04
-rw-r----- 1 milosz milosz  44M 2011-02-27 16:28 file.png

You can merge them in a couple of different ways.

$ cat file1.part0{0,1,2,3,4} > file_m.png
$ diff file.png file_m.png
$
$ ls -1 file1.* | sort | xargs cat > file_m2.png
$ diff file.png file_m2.png
$
$ cat file1.part0* > file_m1.png
$ diff file.png file_m1.png
$
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu