| Notices |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
|
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
Code:
kristijan@slackware testing$ split -b 1945k karaoke.mp3
kristijan@slackware testing$ ls -lh
total 26M
-rw-rw-r-- 1 kristijan users 13M Jul 23 18:18 karaoke.mp3
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r-- 1 kristijan users 1.4M Jul 23 18:22 xag
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)
Code:
kristijan@slackware testing$ rm karaoke.mp3
kristijan@slackware testing$ ls -lh
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r-- 1 kristijan users 1.4M Jul 23 18:22 xag
kristijan@slackware testing$ cat xa* > karaoke-restored.mp3
kristijan@slackware testing$ ls -lh
total 26M
-rw-rw-r-- 1 kristijan users 13M Jul 23 18:39 karaoke-restored.mp3
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r-- 1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r-- 1 kristijan users 1.4M Jul 23 18:22 xag
kristijan@neo testing$
By using cat, we have now recreated the original file. The 'xaa', xab' etc files may now be deleted.
There we have it, the karaoke file is now restored and can be played as per normal.
|
|
|
|
All times are GMT -5. The time now is 06:14 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|
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.