How to recursively bzip2 files in a folder to a single bz2 file

0

I have this problem, where I need to find all files with a particular name and zip all of them into a single zip file.

I tired things like

find . -not -name "*bz2" -name "myname*"  -exec bzip2 test.bz2 {} +;

and

find . -not -name "*bz2" -name "myname*"  -exec bzip2 test.bz2 {} /;

and many others, but its always zipping them separately. In need it to be a bzip file.

Paddy Mahadeva

Posted 2017-05-23T11:25:39.067

Reputation: 13

Answers

2

Bzip cannot concatenate multiple files into a single archive (like ZIP). Bzip is just for compressing a single file (like Gzip).

If you want to include multiple files in a compressed archive, use Tar first to create an archive of multiple files, and then bzip that single archive.

You could use:

 find . -not -name "*bz2" -name "myname*" | xargs tar -jcvf archive.tar.bz2 

xargs will put all the file names that find found after the Tar command (normal syntax for tar is tar -jcvf archivename.tar.bz2 file1 file2 file3 ...).

mtak

Posted 2017-05-23T11:25:39.067

Reputation: 11 805