7-Zip Command Line Switch for Compression Method

This article explains how to specify and configure compression methods in the 7-Zip command-line utility, focusing on the -m switch. You will learn the exact command syntax required to switch algorithms to formats like PPMd, adjust algorithm-specific parameters, and run practical examples to optimize your file archives.

The Compression Method Switch: -m

In the 7-Zip command line (7z), the switch used to specify the compression method is -m (Method).

To define a specific algorithm, use the -m0= parameter followed by the algorithm name. The 0 indicates the first filter in the compression pipeline.

The basic syntax is:

7z a <archive_name> <files_to_compress> -m0=<MethodName>

Supported Compression Methods

7-Zip supports several algorithms depending on the archive format (primarily .7z):

  • PPMd: Highly efficient for plain text, source code, and log files.
  • LZMA / LZMA2: The default general-purpose algorithms offering high compression ratios.
  • BZip2: Standard block-sorting algorithm.
  • Deflate: Standard algorithm used primarily for .zip compatibility.
  • Copy: Stores files without any compression.

Using the PPMd Method

PPMd is an implementation of Dmitry Shkarin's PPMII algorithm. It is particularly effective for compressing text-based data where dictionary-based algorithms like LZMA may be less efficient.

Basic PPMd Command

To create an archive using PPMd compression:

7z a archive.7z *.txt -m0=PPMd

Advanced PPMd Parameters

PPMd allows you to fine-tune memory usage and model order using sub-parameters separated by colons (:):

  • mem (Memory Size): Specifies the amount of RAM allocated for the model (e.g., mem128m or mem1g). The default is typically 24m.
  • o (Model Order): Controls the context depth used for prediction, ranging from 2 to 32. The default is 6. Higher orders can increase compression ratios on large text files but require more processing time.

Example with Custom Parameters

To compress a directory of log files using PPMd with 256 MB of memory and a model order of 16:

7z a logs.7z /var/log/ -m0=PPMd:mem256m:o16

Combining -m with Other Compression Settings

The -m switch also controls broader archive properties when configured without the method index 0:

  • Compression Level (-mx): Sets overall compression effort from store to ultra (-mx0 to -mx9).
  • Multithreading (-mmt): Sets the number of CPU threads (e.g., -mmt=4 or -mmt=on). Note that PPMd natively supports single-threaded operation per data stream.

Full Example

To create a maximum-compression archive using PPMd:

7z a output.7z documents/ -mx9 -m0=PPMd:mem512m:o12