Linux 7z Command

Linux 命令大全Linux Command Encyclopedia

7z is a powerful file compression and decompression tool in Linux, supporting multiple compression formats.

7z is an open-source file compression tool that uses LZMA and LZMA2 compression algorithms, providing extremely high compression ratios. It supports multiple compression formats, including:

  • .7z(default format)
  • .zip
  • .gzip
  • .bzip2
  • .tarwait

Install 7z

In most Linux distributions, 7z is part ofp7zipthe 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 <command> [options] <archive_name> [files...]

Common Options

CommandDescription
aAdd files to archive
eExtract files (ignoring directory structure)
xExtract files (preserving directory structure)
lList archive contents
dDelete files from archive
tTest 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 from archive

7z d archive.7z file_to_delete.txt

5. Test archive integrity

7z t archive.7z

6. Split archive (multi-volume compression)

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

When extracting split archives, you only need to specify the first volume:

7z x archive.7z.001

Linux 命令大全Linux Command Encyclopedia

Other Extensions