开发者

Possible to combine several bz2 archives into one?

开发者 https://www.devze.com 2023-03-25 18:31 出处:网络
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 opti

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 (ye开发者_开发技巧s 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)?


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.


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


You should flip the question around - you should not try to decompress and then recompress the files, simply make a tar archive of all the separate files - tar is ideal as a container for the separate files.

tar cf tarofbzfiles.tar *.bz2


You can shorten @lacos's answer with the built in bzcat shorthand for bzip2 -dc and pipe back into bzip2 as usual. Not any more correct than @lacos but a little bit slicker ;)

bzcat file*.bz2 | bzip2 >resulting_file.bz2
0

精彩评论

暂无评论...
验证码 换一张
取 消