如何在windows下使用zip命令
# 起因
在前端项目打包部署的时候,常常是本地打好包,利用 shell 工具上传,但是打包的项目通常是多个文件,且目录层级较深,于是想到先压缩,然后在服务端解压,速度更快些。
但是在 windows 的命令行,是不能直接使用 zip 命令的,它是 linux 系统才有的,但是有个软件GnuWin32
,允许在 windows 使用 zip 命令,于是开始撸它。
# 安装
打开官网下载 (opens new window),安装,这里安装路径为C:\Program Files (x86)\GnuWin32
。
然后将 bin 目录(C:\Program Files (x86)\GnuWin32\bin
)添加到系统环境变量 Path。
重启终端,来测试下是否可以使用了。
# 压缩文件
新建文件
mkdir test && cd test && echo hello > hello.txt
1
压缩文件到指定目录
# zip [目录] [文件]
zip hello-zip hello.txt
1
2
2
压缩成功
# 压缩文件夹
先新建目录和文件
mkdir test && cd test && echo hello zip > hello.txt
1
然后使用 linux 压缩命令
cd ..
zip -r test.zip test # 将test目录压缩为test.zip,-r表示递归
1
2
2
ok,压缩成功。
如果想要解压缩,可以参考unzip (opens new window)。
更多 linux 资源包见这里 (opens new window)。
上次更新: 2021/12/07, 19:00:32