How to bzip2 multiple files into one single archive file


I am reading an offline document of bzip2 and I am told that I can compress multiple files into one single archive using bzip2 like this:

bzip2 finalArchive.bz2 file1 file2 file2

But when I try this I get

Can't open input file finalArchive.bz2: No such file or directory.

and I'm getting those 3 files compressed individually as file1.gz2 file2.gz2 and file3.gz2 and I also know that I could cat them into one single file but I want to be ab;e to do that using one single command.

I am able to do just that using zip:

zip file1 file2 file3

and I'm getting the expected file

Cat Hariss

Posted 2018-01-22T00:09:48.643

Reputation: 33



Both bzip2 and gzip work on a single file. When that file is compressed, the uncompressed version is removed. When extracting, the opposite takes place.

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.


Posted 2018-01-22T00:09:48.643

Reputation: 2 634

So you are saying that there is no such thing as this command: bzip2 finalArchive.bz2 file1 file2 file3? – Cat Hariss – 2018-01-22T00:19:20.957


The most common Unix compression utilities (gzip, bzip2, xz) all operate on single files, and the standard way to make a multi-file archive is to combine them with tar.

You get the Can't open input file finalArchive.bz2: No such file or directory. error because bzip2 thinks you want to compress a file called finalArchive.bz2, which of course doesn't exist.

To accomplish what you want, use this command:

tar -cjf finalArchive.tar.bz2 file1 file2 file3

where the j option tells tar to use bzip2 to compress the tar archive. See the relevant section in the tar manual for more about this.

If you are using a very old version of tar without compression support, you would need do the compression step manually:

tar -cf - file1 file2 file3 | bzip2 -c > finalArchive.tar.bz2


Posted 2018-01-22T00:09:48.643

Reputation: 12 964


Remove just input the list of files. Example screenshot below:

enter image description here


Posted 2018-01-22T00:09:48.643

Reputation: 168