Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to combine several bz2 archives into one?

I have several (27) huge (several GB each) bz2 archive files that I need combined into one bz2 archive. Uncompressing them and then creating a new archive from what was just uncompressed is not an option for me, since compressed, all 27 files add up to about 100GB, and uncompressed it's about 5-6TB (yes that's TERAbytes lol).

Can this be done with some sort of script, or is there even another compression format that allows for this to be done (easier)?

like image 770
dmn Avatar asked Aug 04 '11 17:08

dmn


People also ask

How to bzip2 multiple files?

To put multiple files into a bzip2 archive, first use tar to get them into one file, then compress that one file. Or since tar is "zip aware" you can use the -j flag to use bzip2 compression when you create the tar archive all as one step.

How to compress multiple files into one in Linux?

In order to zip multiple files using the zip command, you can simply append all your filenames. Alternatively, you can use a wildcard if you are able to group your files by extension.

Which command is used to combine multiple files into single archive in Unix?

In Unix and Unix-like operating systems (such as Linux), you can use the tar command (short for "tape archiving") to combine multiple files into a single archive file for easy storage and/or distribution.

What do I do with BZ2 files?

bz2 files work natively and are used by default for saving all source code software program files. If, however, you are using Windows or Mac devices then you will need WinZip to compress, extract and archive tar. bz2 files.


2 Answers

You can simply concatenate many bz2 files into single bz2 file, like that:

$ cat file1.bz2 file2.bz2 file3.bz2 >resulting_file.bz2

bzip2 and other utilities like lbzip2 will be able to decompress the resulting file as expected.

like image 160
Mikołaj Izdebski Avatar answered Sep 20 '22 15:09

Mikołaj Izdebski


If you're willing to burn a few days of CPU, here's one solution with the magical pipe facility of modern UNIX(R) operating systems:

bzip2 -dc file*.bz2 | bzip2 >resulting_file.bz2

... actually, grab lbzip2 version 2.0, and do the same, except with lbzip2, on a multicore:

lbzip2 -dc file*.bz2 | lbzip2 >resulting_file.bz2
like image 39
lacos Avatar answered Sep 21 '22 15:09

lacos