Split Large Files and Rebuild Them

The other day I needed to transfer a 3.8G file over ftp. The problem was that the ftp server timed out and logged me out when only around a third of the file was transferred.

So I needed to split the file into small chunks and send those. Then you have the problem of sticking all the fragments back together again. Thankfully I’m not on Windows 🙂 I use Linux so this was all done with standard Linux commands.

First I split the file into 500Mb fragments.

split -b 500m myfile

This gave me the following

-rw-r--r--  1 richard richard 3.8G Jul 29 12:08 myfile
-rw-r--r--  1 richard richard 500M Jul 31 08:28 xaa
-rw-r--r--  1 richard richard 500M Jul 31 08:29 xab
-rw-r--r--  1 richard richard 500M Jul 31 08:29 xac
-rw-r--r--  1 richard richard 500M Jul 31 08:29 xad
-rw-r--r--  1 richard richard 500M Jul 31 08:30 xae
-rw-r--r--  1 richard richard 500M Jul 31 08:30 xaf
-rw-r--r--  1 richard richard 500M Jul 31 08:30 xag
-rw-r--r--  1 richard richard 326M Jul 31 08:31 xah

Once I had transferred the file, I needed to put it back together again. As the files are split and use an alphabetical sequence in their names we can use the magic of pattern matching to put them back in the right order. There is no need to name all the files.

cat xa? > myfile

Leave a Reply

Your email address will not be published. Required fields are marked *