Tuesday, December 22, 2009

Split files into parts easily in bash

These days, USB sticks have obliterated the worry of not being be able to carry computer files from one computer to another.  However, there will be instances when you'll be tempted to email a file to someone and that file will be too big to attach to your email.  Whatever do you do!?!

This is where the split command in your Linux terminal comes in handy.  Let's say you have an .mpg file that runs for roughly 25 minutes and happens to take up 40 megabytes (e.g. 'speeches from wedding video.mpg').  Let's also say that your email server will accept attachments of maximum 10 megabytes.  So, we know that we need to split this .mpg file into 4 parts of 10 megabytes each.

Here's the command to use for the example file:

split -b 10000k 'speeches from wedding video.mpg' speeches.

Here's what the arguments mean:

  • -b tells the split command that you want to specify the 'byte' size
  • 10000k, or 10,000 kilobytes is the size of the parts we wanted (10,000 kilobytes = 10 megabytes)
  • 'speeches from wedding video.mpg' is the file we want to split into parts
  • speeches. tells the split command that all part files should begin with 'speeches.'
This will result in the creation of 4 new 10 meg files named:

  • speeches.aa, speeches.ab, speeches.ac, speeches.ad
Putting them back together again

Admittedly, this is a solution where the other person has to be a Linux user.  The person on the other end has to navigate to the directory where the part files are stored and enter in the following command:

cat speeches.?? > 'speeches from wedding video.mpg'

Voila!  Humpty dumpty has been put back together again :)

This neat Linux trick has been brought to you by an awesome book I'm currently reading called Linux All-in-One Desk Reference For Dummies.  I heartily recommend it to Linux newbies!


  1. where should the file "speeches from wedding video.mpg" be placed. there is no pathway specified..

  2. the command I specified breaks the file up into parts in the same directory.

  3. split -l 10 file1 file99

    it is not work.......there is no contents in the file99............pls help