I recently needed to compress images using one of the best compression types available, lzma. I did some research and with the help of commandlinefu and google, I was able to find what I was looking for.

7z a -t7z -m0=lzma -mx=9 -ms=on file.7z file.img

The above uses lzma with the best compression selected. “file.7z” is the resulting file while “file.img” is the source file to compress.

7z a -t7z -m0=lzma2 -mx=9 -ms=on file.7z file.img

The above command uses lzma2, a newer version of lzma with better compression using multiple core’s as well as compressing already compressed content a lot more efficiently.
I noticed using lzma2 that compression and decompression time was faster as more of my processor was used for the job.

If you are a one-liner type of person, may I suggest the following:

dd if=/dev/sda | 7z a file.7z -si -m0=lzma2 -mx=9 -ms=on

The above will perform a dd copy of /dev/sda and pass it to 7zip which will compress the stream with lzma2 and name it file.7z

Blog Logo

Mario Loria


Published

Image

./scriptthe.net

Because 127.0.0.1 gets old after a while.

Back to Overview