How do I compress multiple files into one archive using lzma?

4

1

Looking at the options of xz and lzma, I can't for the life of me figure out how to compress multiple files into one archive. I know it is possible because I've uncompressed a .lzma file and it opened a ton of songs.
If i try doing lzma -k file file file file it just compresses each one individually. Is there an obvious option or argument I'm missing?

jackcogdill

Posted 2013-01-22T16:51:41.970

Reputation: 207

Answers

7

One thing you could do is use tar:

tar cf files.lzma --lzma file1 file2 ... fileN

Or, simpler,

tar cf files.lzma --lzma file*

That creates the files.lzma archive which you can then unpack using:

tar xf files.lzma

terdon

Posted 2013-01-22T16:51:41.970

Reputation: 45 216

@tink While it's true that the standard Linux archiving tools (gzip, bzip2, xz, etc.) can only compress single files, you can combine those files into a tar archive first and then compress the archive. This is generally accepted practice on *nix systems, and can even be done directly within tar by using the -z (gzip), -j (bzip2), or -J (xz) switches to automatically compress the archive stream after creation (check your system's tar man page for the exact switches since they can differ between systems/implementations). – Nathan2055 – 2019-05-02T03:17:29.280

It's worthwhile to point out that, unlike zip, rar, arj on windows et al the common tools on unix/linux systems operate on streams, hence commonly have no option to create a single archive file. – tink – 2013-01-22T19:12:13.463

@tink what common tools are you referring to? gzip and tar can. – terdon – 2013-01-22T19:16:15.073

gzip, bzip2, compress ... I can't see any mention of compressing several files into one archive using gzip alone. Concatenating the content of several files into one using -c with a redirect doesn't count :) – tink – 2013-01-22T21:12:30.430

0

man lzma

EXAMPLES

Basics

Compress the file foo into foo.xz using the default compression level (-6), and remove foo if compression is successful:

xz foo

Decompress bar.xz into bar and don't remove bar.xz even if decompression is successful:

xz -dk bar.xz

Create baz.tar.xz with the preset -4e (-4 --extreme), which is slower than e.g. the default -6, but needs less memory for compression and decompression (48 MiB and 5 MiB, respectively):

tar cf - baz | xz -4e > baz.tar.xz

A mix of compressed and uncompressed files can be decompressed to standard output with a single command:

xz -dcf a.txt b.txt.xz c.txt d.txt.lzma > abcd.txt

linuxUser

Posted 2013-01-22T16:51:41.970

Reputation: 1