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

相关推荐
未济3 天前
linux 配置环境变量
linux
傲世仙尊3 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.3 天前
进程间通信
linux
AI职业加油站3 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-053 天前
Linux IO编程——静态库、动态库
linux
此冬歌咏3 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz3 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅3 天前
linux(8) 软硬链接
linux·运维·服务器
AIgorithmGEEK3 天前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid