p7zip-full、unzip 和 tar 是 Linux 下常用的压缩与解压工具,以下是它们的常见用法整理。
🔧 安装命令
apt install -y p7zip-full unzip tar📦 1. 7z(来自 p7zip-full)
✅ 解压 .7z 文件
7z x file.7z📁 压缩文件/文件夹为 .7z
7z a archive.7z file_or_folder🔍 查看压缩包内容
7z l archive.7z📂 解压到指定目录
7z x file.7z -o/path/to/dir⚠ 注意:
-o后面不能有空格!
🗂️ 2. unzip(解压 .zip 文件)
✅ 解压 zip 文件
unzip file.zip📂 解压到指定目录
unzip file.zip -d /path/to/destination📝 解压时覆盖已有文件
unzip -o file.zip🔍 仅列出文件内容(不解压)
unzip -l file.zip📁 3. tar(解压 .tar 系列文件)
✅ 解压 .tar
tar -xvf file.tar✅ 解压 .tar.gz / .tgz
tar -xzvf file.tar.gz✅ 解压 .tar.bz2
tar -xjvf file.tar.bz2✅ 解压 .tar.xz
tar -xJvf file.tar.xz📂 指定解压目录
tar -xzvf file.tar.gz -C /path/to/destination🔍 查看压缩包内容
tar -tvf file.tar.gz📝 附录:常用参数速查
| 参数 | 含义 |
|---|---|
x | 解包(extract) |
v | 显示详细过程 |
f | 指定文件名 |
z | 支持 gzip 解压 |
j | 支持 bzip2 解压 |
J | 支持 xz 解压 |
-C | 指定解压目录 |
