Tuesday, June 02, 2009

Split -- another very useful CLI command I didn't know about

I found out about split in this post. Note that it's also worth reading the comments in this post.
But just taking split on its own is very worth while. Here's a useful tutorial on how to use split although it's really little more than the split man pages but does give a few examples.
As an example of how split could be useful, suppose you want to email music album to someone. Problem is that the most popular email clients don't allow more than 20 MB of attachments.
So, I'm going to show you how to do this using the tar and split functions.
First, I'm going to do this with an album I like a lot "The Royal Scam" by Steely Dan.
So, now I have to get this album (95.2 MB) into one file like this

tar -cvzpf royalscam.tgz royalscam

(where the album folder is called royalscam and is located in the home directory from where I'm running this command)
Next, I need to split it into pieces less than 20 MB and that's where split comes in
# split -b 19m royalscam.tgz royalscaminparts

Running this command gave me 5 new files called royalscaminpartsa* where *=a, b, c, d and e.
So, now I can email them as attachments in Gmail.
On receipt, obviously each of the five parts have to be downloaded to the same folder. Then, in this folder, run this command
# cat royalscaminpartsa* > royalscamnew

Now, you generate a new file (which of course is a .tgz file) which can be expanded with the following, and final, command:
tar -zxvf royalscamnew

and you end up with the album ready to play.

No comments:

Post a Comment