Splitting Files with split


Splitting Files with split

Suppose you're futzing with your new digital camera and want to share a photo of your new computer (what else is cool enough to take pictures of?!) via email with your friends and family. You access the file, attach it to an email message, and thenargh!your ISP fails to send the file because it's too big. While you could modify the file itselfreduce the physical size, reduce the number of colors used, or crop out nonessential parts, for exampleyou can also just split the file with split. For example, if the ISP tells you that no files larger than 0.51 MB will be accepted, you can use split to send the file in chunksall using one easy command (Code Listing 6.23).

Code Listing 6.23. Use split to break files into smaller chunks.

[jdoe@frazz split]$ ls -lh total 1.1M -rwxrwxr-x    1 jdoe  jdoe     1.0M Jan  1 12:42 mongopicture.jpg* [jdoe@frazz split]$ ls -l total 1060 -rwxrwxr-x    1 jdoe  jdoe     1079300 Jan  1 12:42 mongopicture.jpg* [jdoe@frazz split]$ split -b 500k mongopicture.jpg [jdoe@frazz split]$ ls -lh total 2.1M -rwxrwxr-x    1 jdoe  jdoe     1.0M Jan  1 12:42 mongopicture.jpg* -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 xaa -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 xab -rw-rw-r    1 jdoe jdoe    54K Jan  1 13:03 xac [jdoe@frazz split]$ split -b 500k mongopicture.jpg chunk [jdoe@frazz split]$ ls -lh total 3.2M -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 chunkaa -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 chunkab -rw-rw-r    1 jdoe jdoe    54K Jan  1 13:03 chunkac -rwxrwxr-x    1 jdoe  jdoe     1.0M Jan  1 12:42 mongopicture.jpg* -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 xaa -rw-rw-r    1 jdoe jdoe    500K Jan  1 13:03 xab -rw-rw-r    1 jdoe jdoe    54K Jan  1 13:03 xac  [jdoe@frazz split]$ cat chunkaa chunkab chunkac > reconstitutedpicture.jpg [jdoe@frazz split]$ cmp mongopicture.jpg reconstitutedpicture.jpg [jdoe@frazz split]$ 

To Split Files with split:

  • split b 500k mongopicture.jpg

    With that, split gives you three files (xaa, xab, xac) that are each 500 KB (the first two) or less (the last one, containing the leftovers). Mail each of those, and you've squeaked under the ISP's size limit.

Tips

  • Control the names of the files by adding a prefix at the end. For example, try split b 500k mongopicture.jpg chunk to get three pieces called chunkaa, chunkab, and chunkac.

  • Use cat to restore the original. For example, cat xaa xab xac > reconstitutedpicture.jpg

  • If you're following the photo file example used here, note that the recipient of the emailed file pieces will have to assemble the pieces in order to view the photo. Even if the recipient isn't a Unix user, all systems have utilities to accomplish this task. Now, whether your recipient would want to take the time or would have the skill to do this is another question. You might check with him or her first.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net