chillibear.com

Splitting files

Since I was busy explaining how to do this to people at work yesterday I thought I might post it here. The problem encountered involved copying a 5GB file from a Mac to an external drive (to move it elsewhere), the drive in question was formatted with Fat32. They therefore hit the 4GB file size limit on Fat32 (nice obscure Apple numeric error code 1309 - file bounds error). Anyhow so time to dust off some old Unix commands.

Basically you can use the unix split command to split a file up into data chunks and then move them then rebuild the original file. I wont bother describing all the command options and will just illustrate usage. Open up a terminal window and type:

split -b 500m /path/to/my/big.file

Okay so /path/to/my/big.file is the full path to the file you want to split up - the easy way to get this is to drag the file in question onto the terminal window - the full path will then be pasted in. The -b 500m bit tells the split command to split the file into 500MB chunks, so if you want to split the file into 2GB chunks (approximately) you’d use -b 2000m.

After you run the code split will output chunks of data into new file in the directory your in within terminal (normally your home directory unless you’ve changed).

These files are named xaa, xab, xac, etc.

You can join these files back together using the Unix cat command, concatenating the chunks back together. Rather than concatenating the chunks to the screen we redirect the output into a new file. So say our file was split up into two chunks I’d open up a terminal - switch to the directory containing the chunks and type:

cat xaa xab > rebuilt.file

So that’s cating out both files and redirecting (>) the output into a new file called rebuilt.file. If you’ve got lots of chunks it may be worth using a range indicator thus:

cat xa[a-f] > rebuilt.file

Would cat out: xaa, xab, xac, xad, xae, xaf into rebuilt.file

Written on 09 Jan 2009 and categorised in CommandLine, Macintosh, and NIX, tagged as Split and Fat32

Home, Post archive

site copyright Eric Freeman

Valid XHTML 1.0 Strict