7z Command
The 7z command is a powerful command-line file archiver that supports a high compression ratio. It is part of the 7-Zip open-source project and is widely used for creating and extracting archives.
Syntax
Description
The 7z command is used for archiving files. It supports various compression methods and formats, with its native 7z format offering one of the best compression ratios. It can also handle other popular formats like ZIP, GZIP, BZIP2, and TAR.
Common uses include:
- Creating new archives
- Extracting files from archives
- Listing contents of an archive
- Updating existing archives
- Testing archive integrity
Common Commands and Switches
| Command/Switch | Description |
|---|---|
a |
Add files to archive |
x |
Extract files with full paths |
e |
Extract files without paths |
l |
List contents of archive |
u |
Update files in archive |
t |
Test archive integrity |
-o{dir} |
Set output directory (for extraction) |
-p{password} |
Set password |
-m{method} |
Set compression method |
Examples
Create a 7z archive
Creates myarchive.7z containing file1.txt and folder/.
Extract an archive with full paths
Extracts myarchive.7z to the specified directory, preserving the original directory structure.
Extract an archive to current directory (without paths)
Extracts all files from myarchive.7z directly into the current working directory.
List contents of an archive
Lists all files and folders within myarchive.7z.
Create a password-protected archive
Creates a password-protected archive named secret.7z.