Save 7-Zip Command Line Output to a Text File

Redirecting 7-Zip command line logs to a text file allows you to record archiving operations, track errors, and review automation tasks. This guide covers how to capture standard output and error messages from the 7-Zip command line utility (7z.exe) using standard stream redirection operators in Windows Command Prompt, PowerShell, and Linux terminals.

Basic Output Redirection

In Windows Command Prompt and Linux shells, you redirect standard output to a text file using the greater-than symbol (>).

To create a new log file or overwrite an existing one:

7z a archive.zip C:\Data\* > log.txt

To append output to an existing log file rather than overwriting it, use the double greater-than operator (>>):

7z a archive.zip C:\Data\* >> log.txt

Capturing Both Standard Output and Errors

By default, the > operator only redirects standard output (stdout). If 7-Zip encounters an error, that message is sent to standard error (stderr) and will still appear on the console screen instead of your log file.

To capture both normal status messages and error logs into a single file, redirect stderr (stream 2) to stdout (stream 1) using 2>&1:

7z a archive.zip C:\Data\* > log.txt 2>&1

If you prefer to separate standard logs from error reports, redirect the two streams to distinct files:

7z a archive.zip C:\Data\* > output.log 2> error.log

Increasing Log Detail with the Verbosity Switch

7-Zip provides the -bb switch to control log verbosity. Adding this switch provides more detailed output inside your generated text file, such as listing every file processed.

  • -bb0: Disable all log output.
  • -bb1: Standard logging (default).
  • -bb2: Show deleted files during update operations.
  • -bb3: Show all processed files, compression ratios, and detailed file attributes.

Example with maximum verbosity:

7z a archive.zip C:\Data\* -bb3 > detailed_log.txt 2>&1

PowerShell Syntax

If you are running the command in PowerShell, standard redirection works similarly, but capturing both streams requires either PowerShell's *> all-stream redirection operator or standard redirection:

7z a archive.zip C:\Data\* *> log.txt

Alternatively, you can pipe the output to Out-File:

7z a archive.zip C:\Data\* -bb3 2>&1 | Out-File -FilePath .\log.txt -Encoding utf8