Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By Kristijan at 2004-07-23 04:37
=====================
Split and Reassemble files
=====================
There always comes a time, where you wish that file was only a few kilobytes/megabytes smaller. Wether it be so it can fit onto your floppy disk, CDR etc, or so you can meet the attachment limit on an e-mail server. This isn't really a command that you would use everyday, but it might come in handy.
Splitting the file (split)
=================
Now, for this example I will use the file 'karaoke.mp3' which is 13M
Code:
kristijan@slackware testing$ ls -lh
total 13M
-rw-rw-r-- 1 kristijan users 13M Jul 23 18:18 karaoke.mp3
Just say we wanted to e-mail this file to a friend, but the e-mail server only allowed a maximum of 2M attachments.
(Note** I like to play safe, so I will make my chunks of data 1.9M)
1.9 x 1024 = 1945.6
(Note** To play safe once again, I will leave out the decimal and just use 1945)
The command that we will use is $ split -b 1945k karaoke.mp3
OK, what we have now done is told 'split' to use bytes per output file (-b). For more information and arguments on split, view the man pages (man split). Split how now 'split' karaoke.mp3 into 7 smaller files named 'xaa', 'xab', 'xac' etc, which are all under 2M in size.
These files now meet the e-mail server's attachment limit and can be sent.
Recreating the file (cat)
==================
Recreation of the karaoke.mp3 is even easier. For this, we will be using 'cat'. See the man pages for more information on 'cat' (man cat).
The command that we will use is $ cat xa* > karaoke-restored.mp3
(Note** Before removing the original file, I recommend that you make a backup of it)
I'd suggest to take the md5sum of the original file, to send it along as "karaoke.mp3-md5sum"-text file and compare the newly created file's md5sum with the original, just to make sure nothing happened during emailing.
by merlinblack on Tue, 2012-10-23 23:29
I've found another use for split - putting very large files, in my case dmg archives from a Mac, onto a FAT32 formated USB external HDD. Xcode weighs in at 4.1GB. Too big for FAT32.
In addition to the email example above, I could imagine if rsync'ing or scp'ing large files over a WAN, you may want to chop the file up so you can restart with out starting from scratch.
The split program of course exists on Mac's (basically BSD) as well as Linux.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
I'd suggest to take the md5sum of the original file, to send it along as "karaoke.mp3-md5sum"-text file and compare the newly created file's md5sum with the original, just to make sure nothing happened during emailing.
In addition to the email example above, I could imagine if rsync'ing or scp'ing large files over a WAN, you may want to chop the file up so you can restart with out starting from scratch.
The split program of course exists on Mac's (basically BSD) as well as Linux.