26 May 2010

Packing files together, then splitting them: tar

The tar program is so useful for packing files together for transport.  With all the talk of cloud storage and all, especially now with Ubuntu One, there's still sometimes a place for good ol' email it to yourself storage.  Except that email servers typically won't let you upload files larger than 10 or 20 MB.

The solution is to archive the files into one, then split it into say 10 MB segments.

Say all the files are in a directory src-code.  Then do tar -czf src-code.tgz src-code.  That'll pack the whole directory into one zipped and archive file.

Then to split it into approximately 10 MB segments, do tar -ML 10240 -cf src-code.part1.tgz src-code.tgz. This will return an interactive session, where it'll ask you for the name of the next segment to save as, at which point you'll want to do n src-code.part2.tgz for the second segment, and so on (do ? and return-key for help).

To reverse the process, do tar -Mxf src-code.part1.tgz and then n src-code.part2.tgz and so on at the interactive prompt.  Then tar -xzf src-code.tgz to get back the src-code directory.

No comments: