Unix Tip: Reassembling very large "split" files

January 30, 2008, 06:38 PM —  ITworld — 

One of the unwritten rules of computing says that, as various storage media grow in size, so do the files that are written to them. I recently found myself staring at two files, each roughly 4 GB in size, that needed to be combined into one before the file could be decompressed and its contents extracted. What I was expecting to work with was a large cpio archive.


I had loaded each of the file components from a DVD, thus the reason that the file had to be compressed and then broken into two pieces, each of which could be written to a DVD.



The files had the extensions gzaa and gzab. This naming convention is meant to tell the recipient of the files that 1) the files are both chunks of a larger file that needs to be reassembled and 2) that the resultant file is gzipped. These names also suggest that the original file was broken into two pieces with the "split" command -- a convenient utility that breaks files into smaller pieces and names the pieces and appends "aa", "ab" and so on to give each chunk of the original file a distinct name.



To reassemble the file from its components, I used the cat command, basically adding the contents of the second file to the end of the first. While this may seem like an obvious solution, I had never done this before with compressed cpio files or with files of this size. The rebuild of the original file took a long time, but worked perfectly. I soon had a file nearly 8 GB in size named bigfile.gzaa.

# cat bigfile.gzab >> bigfile.gzaa

This concatenation operation took a long time to run. I was, after all, reading and writing nearly 4 GB of disk contents. Rejoining files with cat takes one less operation than files you have to join together. If I had two more files, I would have run these commands as well:

# cat bigfile.gzac >> bigfile.gzaa
# cat bigfile.gzad >> bigfile.gzaa

Some people prefer to first rename the original file (e.g., mv bigfile.gzaa to bigfile.gz) before starting the concatenations so that the file they are assembling has the intended name while it's being rebuilt. Others rename the file after the file has been rebuilt.



In my case, once bigfile.gzaa contained both chunks of the original file, I removed bigfile.gzab to recover the 4GB of disk space that it occupied and renamed bigfile.gzab to the more familiar form, bigfile.gz.



At this point, I could unzip bigfile.gz and recover bigfile -- the cpio file that I was expecting when I first mounted the DVDs. The unzipping of bigfile.gz also took a long time to complete (approximately half an hour I would guess). The cpio file was more than 13 GB. Without the gzip compression, it would have required four DVDs instead of the two that it occupied when I received it.



If you have a large file that won't fit on a single DVD, you can use the reverse of the process that I used to break your file into appropriately sized pieces and write your DVDs. The split command can create a series of 4 GB chunks with a command like this:

# split -b 4000m bigfile.gz bigfile.gz

The 4000m argument means 4,000 MB or 4 GB. The bigfile argument on the end of the line tells split to name your files bigfile.gzaa, bigfile.gzab and so on. Without this, split will give your files the simpler names aa, ab etc.



Working with very large files is not much different than working with smaller files as long as you have enough disk space, enough time and some insights into the files' format.

 

ITworld

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff

Enterprise 2.0 Implementation
By Aaron C. Newman, Jeremy Thomas
Published by McGraw-Hill
Learn more!

Deploying Cisco Wide Area Application Services
By Zach Seils, Joel Christner
Published by Cisco Press
Learn more!

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources