Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux 7z Command

Linux 7z Command

Linux Command Reference Linux Command Reference

7z is a powerful file compression and extraction tool on Linux, supporting multiple compression formats.

7z is an open-source file compression tool that uses the LZMA and LZMA2 algorithms to provide very high compression ratios. It supports many compression formats, including:

Install 7z

On most Linux distributions, 7z is p7zip part of the package:



# Ubuntu/Debian

sudo apt install p7zip-full



# CentOS/RHEL

sudo yum install p7zip



# Arch Linux

sudo pacman -S p7zip

After installation, you can verify with the following command:



7z --version

Basic Syntax

7z  [options]  [files...]

** Common Options**

Command Description
a Add files to an archive
e Extract files (ignore directory structure)
x Extract files (preserve directory structure)
l List archive contents
d Delete files from an archive
t Test archive integrity

Basic Usage

1. Compress files/directories



7z a archive.7z file1.txt file2.txt       # 压缩文件

7z a archive.7z dir/                     # 压缩目录

7z a -tzip archive.zip file.txt          # 指定格式为 ZIP

7z a -p123456 archive.7z file.txt        # 加密压缩(密码:123456)

2. Extract files



7z x archive.7z                          # 解压到当前目录

7z x archive.7z -o/path/to/extract       # 解压到指定路径

7z x -p123456 archive.7z                # 解压加密压缩包

3. List archive contents



7z l archive.7z

4. Delete files inside an archive



7z d archive.7z file_to_delete.txt

5. Test archive integrity



7z t archive.7z

6. Split (volume) compression



7z a -v100M archive.7z large_file.dat    # 按 100MB 分卷

To extract a split archive, you only need to specify the first volume:



7z x archive.7z.001

Linux Command Reference Linux Command Reference