Force 7-Zip to Overwrite Files via Command Line

When automating archive extraction using the 7-Zip command-line tool, handling duplicate file conflicts is essential to prevent interactive prompts that halt automated scripts. This guide details the specific overwrite flag used by 7-Zip, explains its exact syntax, and outlines alternative overwrite behaviors available for command-line workflows.

The Overwrite Flag: -aoa

The command-line switch that forces 7-Zip to overwrite all existing destination files without prompting is -aoa.

The -ao switch specifies the overwrite mode, and the trailing a stands for "Overwrite All." When this flag is included in your command, 7-Zip automatically replaces any conflicting destination files with the versions from the archive.

Syntax and Examples

The -aoa switch can be used with either the x (extract with full paths) or e (extract flat) commands. Note that 7-Zip switches do not require a space between the switch identifier and its parameters.

Basic extraction with full paths:

7z x archive.zip -aoa

Extracting to a specific destination directory:

7z x archive.7z -o"C:\DestinationFolder" -aoa

Extracting silently in a batch or shell script:

7z x archive.tar.gz -o/path/to/destination -aoa -y

(The -y switch assumes "yes" to all other non-overwrite system queries, ensuring completely non-interactive execution).


Alternative -ao Overwrite Modes

7-Zip provides four distinct variants under the -ao switch to control conflict resolution:

  • -aoa (Overwrite All): Replaces all existing files with identical names in the destination directory without asking.
  • -aos (Skip): Skips the extraction of any file that already exists at the target location, preserving the existing file.
  • -aou (Auto-rename Extracting): Extracts the file but renames the newly extracted file (e.g., file_1.txt) if a conflict exists.
  • -aot (Auto-rename Existing): Renames the file that already exists on disk and writes the extracted file with the original name.