Linux / macOS 环境下解压 ZIP 文件的标准命令与常用变体

以下为 Linux / macOS 环境下解压 ZIP 文件的标准命令与常用变体,按工程使用频率整理。


一、最常用解压命令

bash 复制代码
unzip file.zip

说明:

  • 解压到 当前目录
  • 自动创建 ZIP 内部的目录结构

二、解压到指定目录(最常用)

bash 复制代码
unzip file.zip -d /path/to/output_dir

示例:

bash 复制代码
unzip data_20251222.zip -d /home/qzq/data/

三、查看 ZIP 内容(不解压)

bash 复制代码
unzip -l file.zip

用于:

  • 确认内部文件名
  • 判断是否路径过深 / 文件名过长

四、覆盖 / 不覆盖策略(重要)

1️⃣ 覆盖已存在文件(不询问)

bash 复制代码
unzip -o file.zip

2️⃣ 不覆盖已存在文件

bash 复制代码
unzip -n file.zip

五、处理中文乱码(非常关键)

如果 ZIP 是 Windows / GBK 编码 生成的(你这个场景很常见):

bash 复制代码
unzip -O GBK file.zip

或(部分系统):

bash 复制代码
unzip -O CP936 file.zip

六、只解压指定类型文件

bash 复制代码
unzip file.zip "*.jpg"

解压到指定目录:

bash 复制代码
unzip file.zip "*.jpg" -d images/

七、排除指定文件/目录

bash 复制代码
unzip file.zip -x "__MACOSX/*"

八、路径过长 / 解压失败时的工程处理建议

如果你再次遇到类似:

复制代码
filename too long

建议流程:

bash 复制代码
mkdir /tmp/unzip_test
cd /tmp/unzip_test
unzip /path/to/file.zip

或:

bash 复制代码
unzip file.zip | head

先确认内部文件名长度。


九、如果系统没有 unzip

Ubuntu / Debian

bash 复制代码
sudo apt install unzip

CentOS / Rocky / Alma

bash 复制代码
sudo yum install unzip

相关推荐
orion5720 小时前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
小猿姐2 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
Mintimate2 天前
WorkBuddy 上手: 让脚本项目 Homebrew CN 变成会排障的 Agent
macos·边缘计算·agent
SkyWalking中文站2 天前
认识 Horizon UI · 5/17:3D 基础设施地图
运维·监控·自动化运维