📅  最后修改于: 2023-12-03 15:24:16.589000             🧑  作者: Mango
在 Linux 终端中,我们可以使用命令行来提取 zip 文件。下面我们介绍一些常用的命令:
unzip
是一个通用的解压缩工具,可以提取几乎所有类型的压缩文件,包括 zip 文件。使用 unzip
命令,可以轻松地在 Linux 终端中提取 zip 文件。
unzip [options] filename.zip [-x files-to-exclude]
常见的选项包括:
-d
:指定解压缩目标目录;-j
:只提取压缩文件中的文件,而不包含目录结构;-o
:覆盖已存在的文件;-q
:安静模式,不显示提取进度。将 example.zip
解压缩到当前目录:
unzip example.zip
将 example.zip
解压缩到 /home/user/Documents
目录下,并覆盖已存在的文件:
unzip -o example.zip -d /home/user/Documents
只解压缩 example.zip
中的 file1.txt
和 file2.txt
文件:
unzip example.zip file1.txt file2.txt
7zip
是一个高压缩比的压缩工具,支持几乎所有类型的压缩文件。与 unzip
不同的是,7zip
还支持一些高级功能,例如加密、自解压缩等。
在 Debian/Ubuntu 系统中安装 7zip
:
sudo apt-get install p7zip-full
在 RedHat/CentOS 系统中安装 7zip
:
sudo yum install p7zip-full
7z [options] filename.zip [-x!files-to-exclude]
常见的选项包括:
-d
:指定解压缩目标目录;-p
:指定密码(加密压缩文件时使用);-m
:指定压缩方法;-y
:自动应答所有提示。将 example.zip
解压缩到当前目录:
7z x example.zip
将 example.zip
解压缩到 /home/user/Documents
目录下,使用密码 abc123
:
7z x example.zip -pabc123 -o/home/user/Documents
只解压缩 example.zip
中的 file1.txt
和 file2.txt
文件:
7z x example.zip file1.txt file2.txt
无论是 unzip
还是 7zip
,都可以在 Linux 终端中方便地提取 zip 文件。 不同的压缩工具有不同的使用方法和支持的功能,程序员可以根据自己的需求选择适合自己的工具。