Skip to main content
The extract commands extract files from archives. 7-Zip provides two extraction commands:
  • x - eXtract files with full paths
  • e - Extract files without directory structure

Syntax

7z x [<switches>...] <archive_name> [<file_names>...] [@listfile]
7z e [<switches>...] <archive_name> [<file_names>...] [@listfile]

Difference Between x and e

x (eXtract with paths)

Extracts files with full directory structure preserved.Example: file/data.txtoutput/file/data.txt

e (Extract)

Extracts all files to the same directory, ignoring paths.Example: file/data.txtoutput/data.txt

Common Options

archive_name
string
required
Name of the archive to extract. 7-Zip auto-detects archive type.
file_names
string
Specific files or patterns to extract. If omitted, extracts all files.Example: *.txt or documents/report.pdf
-o{Directory}
string
Set output directory. No space between -o and the path.Example: -o/home/user/output or -oC:\Output
-p{Password}
string
Provide password for encrypted archives. Omit password to be prompted.Example: -pMyPassword or -p (prompts)
-y
flag
Assume Yes on all queries (overwrite without prompting).
-ao{a|s|t|u}
string
Set overwrite mode:
  • a - Overwrite all existing files
  • s - Skip existing files
  • t - Auto-rename extracting file
  • u - Auto-rename existing file
Example: -aoa (overwrite all)
-t{Type}
string
Set archive type (usually auto-detected).Example: -t7z or -tzip
-r
flag
Recurse subdirectories (enabled by default for archives).
-x{Pattern}
string
Exclude files by pattern.Example: -x!*.tmp -x!*.bak
-i{Pattern}
string
Include only files matching pattern.Example: -i!*.txt
-so
flag
Write data to stdout (for piping).
-si
flag
Read archive from stdin.
-spe
flag
Eliminate duplication of root folder for extract command.
-spf
flag
Use fully qualified file paths (include drive letter on Windows).
-snh
flag
Store hard links as links (extract as links, not copies).
-snl
flag
Store symbolic links as links (extract as links, not file contents).
-sni
flag
Store NT security information (Windows).
-sns
flag
Store NTFS alternate streams (Windows).

Examples

Extract archive with full paths

7z x archive.7z
Output:
7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20

Scanning the drive for archives:
1 file, 23456 bytes (23 KiB)

Extracting archive: archive.7z
--
Path = archive.7z
Type = 7z
Physical Size = 23456
Headers Size = 234
Method = LZMA2:24
Solid = -
Blocks = 1

Everything is Ok

Folders: 3
Files: 12
Size:       45678
Compressed: 23456

Extract to specific directory

7z x archive.7z -o/home/user/output

Extract without directory structure

7z e archive.7z
All files extracted to current directory, paths discarded.

Extract password-protected archive

7z x -p archive.7z
Prompts:
Enter password (will not be echoed):
Or provide password directly:
7z x -pMyPassword archive.7z

Extract specific files

7z x archive.7z readme.txt license.txt

Extract files by pattern

7z x archive.7z *.txt -r

Extract and overwrite without prompting

7z x archive.7z -y

Extract and skip existing files

7z x archive.7z -aos

Extract and auto-rename new files

7z x archive.7z -aot
Creates: file.txt, file_1.txt, file_2.txt, etc.

Extract excluding certain files

7z x archive.7z -x!*.tmp -x!*.bak

Extract only specific file types

7z x archive.7z -i!*.jpg -i!*.png

Extract to stdout (piping)

7z x archive.7z -so > output.txt

Extract multi-volume archive

7z x archive.7z.001
Automatically finds and uses all volumes (.001, .002, .003, etc.)

Extract nested archives

7z x archive.tar.gz -so | tar -x

Test before extracting

7z t archive.7z && 7z x archive.7z

Advanced Examples

Extract with progress to stderr

7z x archive.7z -bsp1 2>&1 | grep -v "^$"

Extract preserving timestamps

7z x archive.7z
(Timestamps preserved by default)

Extract case-sensitive (Linux)

7z x archive.7z -ssc

Extract from stdin

cat archive.7z | 7z x -si

Extract multiple archives

for f in *.7z; do 7z x "$f" -o"${f%.7z}"; done

Extract with full paths including drive (Windows)

7z x archive.7z -spf

Overwrite Modes

The -ao switch controls behavior when extracted files already exist:
ModeSwitchBehavior
Overwrite All-aoaReplace all existing files
Skip-aosKeep existing files, skip extraction
Auto-rename (extracting)-aotRename newly extracted files
Auto-rename (existing)-aouRename existing files

Interactive Prompt (default)

Without -ao or -y, 7-Zip prompts for each file:
file.txt already exists. Overwrite? (Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit?

Working with Different Archive Types

ZIP archives

7z x archive.zip

TAR.GZ archives

7z x archive.tar.gz -so | 7z x -si -ttar
Or extract in one step:
7z x archive.tar.gz && 7z x archive.tar

RAR archives

7z x archive.rar

ISO images

7z x image.iso -o/mnt/iso

Split archives

7z x archive.zip.001
The x command is recommended for most use cases as it preserves the directory structure. Use e only when you specifically want all files in one directory.
Using e (extract without paths) can cause file name conflicts if the archive contains files with the same name in different directories. 7-Zip will prompt to overwrite unless -y or -ao is used.
To preview archive contents before extracting, use the list command:
7z l archive.7z

Exit Codes

CodeMeaning
0Success (no errors)
1Warning (non-fatal error)
2Fatal error
7Command line error
8Not enough memory

Build docs developers (and LLMs) love