Friday 20 January 2012

CLKF: Splitting files in linux

Command Line Kung Fu: Splitting files in linux

So I have a flash drive thats pretty irrevocably damaged, and for some reason or another it wont format into NTFS, but happily formats into FAT32 (exFAT is an option that I chose to ignore). And I have a 4.4GB file to transfer.

We all know that storing a file larger than 4GB is not possible on a partition formatted in FAT32 (which is a pretty old Microsoft file system type, when no-one actually had files larger than a few megabytes, now superseded by NTFS in an age when video files, Operating System images and games come at several Gigabytes in size, and a Terabyte is becoming the norm for any PC sold); In any case the solution to this problem was to split the large file into several smaller chunks that would fit on the drive or several drives.


There is a whole heap of tools available to this end, both freeware and commercial. A quick search on google reveals that the choices available are numerous. Any compression program (7Zip ftw!) does file splitting too. What I want is a command line tool, that will do the task as minimalistically as possible.

One of the original linux tools created for this purpose was 'tar', which stands for Tape ARchive, which is able to bundle a file or a collection of files into one (or several) file (essentially a precursor for ZIP without compression) ready to be stored on what was the best form of backup medium in those days, magnetic tape.

So using tar on the command line, heres how to split a file up:

$ tar -cvM --tape-length=1024000 --file=OUTPUT_FILE1.tar ORIGINAL_FILE

The --tape-length parameter accepts data in kilobytes, so 1024000 = 1GB. Just keep entering sequential filenames when it asks for another filename for each part it creates.
And to join files back up:


$ tar -xvM --file=INPUT_FILE1.tar ORIGINAL_FILE


So that works, but it isn't the most simplistic solution; there is also the much more simpler, split and cat commands:


$ split -b 1024m debian.iso debiansplit


and then when I had to join the files back:


$ cat debiansplit* > debian.iso


split command (click to enlarge)


Some more awesome Command Line Kung Fu to the rescue!





No comments:

Post a Comment