Tech Hacks

Splitting and Joining Files in Ubuntu

Ubuntu has a neat application to split large files into smaller chunks(for emails or to burn into disks).  The application splits files into the format <filename>.<extension>.<part>.  The same application can be used to rejoin the files to recreate the original larger file.

Spliting:

To be able to split file you need the application “lxsplit”. It can be installed using the following command:

sudo apt-get install lxsplit

To split a sample file we will consider a file “archive.zip” of the size 5.5Mb and split it into 1Mb chunks:
{adinserter 2}
lxsplit -s archive.zip 1M

The program generates the following output:

Splitting archive.zip into 6 pieces.
archive.zip.001 1048576 bytes
archive.zip.002 1048576 bytes
archive.zip.003 1048576 bytes
archive.zip.004 1048576 bytes
archive.zip.005 1048576 bytes
archive.zip.006 548727 bytes
Done!

The smaller files are stored in the same directory. Split size can be specified as follows: 15M, 100m, 5000k, 30000000b

Joining the smaller files:

To join the chunks of files we again call lxsplit but this time with the -j option and pass the first file of the series as the parameter

lxsplit -j archive.zip.001

It generates the following output:

Creating merged file `archive.zip’.
Complete size: 5791607 in 6 files.
Processing file `archive.zip.001′ …
Processing file `archive.zip.002′ …
Processing file `archive.zip.003′ …
Processing file `archive.zip.004′ …
Processing file `archive.zip.005′ …
Processing file `archive.zip.006′ …
Done!

The resultant file is stored in the same directory.