[ TechDocsCove ]  TechDocsCove en   ↩︎

# Understanding 7z Terminal Program and Its Usage

data compression   shell  

translations: [ es/Español ] · [ fr/Français ] · [ de/Deutsch ]


Table of contents


7z is a versatile and powerful command-line tool used for creating, extracting, and managing compressed archive files. It supports various compression algorithms, providing high compression ratios.

Basic Commands

Creating an Archive

To compress files into an archive using 7z, use the a command followed by the archive’s name and the files you want to compress.

SHELL
# Create an archive named 'archive.7z' with files 'file1.txt' and 'file2.txt' 7z a archive.7z file1.txt file2.txt

Extracting an Archive

To extract files from an archive, use the e command followed by the archive’s name.

SHELL
# Extract files from 'archive.7z' 7z e archive.7z

Listing Contents

To view the contents of an archive without extracting it, use the l command.

SHELL
# List contents of 'archive.7z' 7z l archive.7z

Compression Levels and Formats

Specifying Compression Levels

You can adjust the compression level using the -mx flag followed by a value from 0 to 9, where 0 indicates no compression and 9 is the highest compression level.

SHELL
# Compress with the highest level of compression 7z a -mx9 archive_max.7z file.txt

Choosing Archive Formats

7z supports various archive formats. To specify a format, use the -t flag followed by the format abbreviation.

SHELL
# Create a ZIP archive 7z a -tzip archive.zip file.txt

Password Protection

Adding a Password

To protect your archive with a password, use the -p flag followed by your chosen password.

SHELL
# Create a password-protected archive 7z a -pYourPassword archive_protected.7z file.txt

File Exclusion and Inclusion

Excluding Files

You can exclude specific files or file types using the -x flag followed by the file(s) or wildcard pattern.

SHELL
# Exclude '*.log' files from the archive 7z a archive_excluded.7z folder -x'!*.log'

Including Only Certain Files

To include only specific files or file types, use the -i flag followed by the file(s) or wildcard pattern.

SHELL
# Include only '*.txt' files in the archive 7z a archive_included.7z folder -i'!*.txt'


Created on: Jan 8, 2024


Email shareIcon for sharing via email    Reddit shareIcon for sharing via Reddit    X shareIcon for sharing via X    Telegram shareIcon for sharing via Telegram    WhatsApp shareIcon for sharing via WhatsApp    Facebook shareIcon for sharing via Facebook    LinkedIn shareIcon for sharing via LinkedIn



Discover More within this Subject: