如何使用cmd行压缩文件? [英] How to zip a file using cmd line?

查看:138
本文介绍了如何使用cmd行压缩文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用蝙蝠文件命令来压缩目录。

I want to zip a directory using bat file command.

例如,如果我想解压缩文件,则可以使用 jar xf file.zip bat文件命令。

For example if i want to unzip a file means i can use jar xf file.zip bat file command.

就像我想要命令行代码来压缩目录一样。

Like that i want command line code to zip a directory.

推荐答案

如果您使用的是Ubuntu Linux:



If you are using Ubuntu Linux:


  1. 安装 zip

sudo apt-get install zip


  • 压缩文件夹:

  • Zip your folder:

    zip -r {filename.zip} {foldername}
    




  • 如果您使用的是Microsoft Windows:



    尽管自Windows Plus以来Windows Explorer本身就支持Zip文件,但Windows并未附带命令行zip程序!

    If you are using Microsoft Windows:

    Windows does not come with a command-line zip program, despite Windows Explorer natively supporting Zip files since the Plus! pack for Windows 98.

    我建议使用开源的7-Zip实用程序,该实用程序包含命令行可执行文件,并支持许多不同的存档文件类型,尤其是其自己的 *。7z 格式,与传统(PKZIP) *。zip 文件相比,压缩率更高:

    I recommend the open-source 7-Zip utility which includes a command-line executable and supports many different archive file types, especially its own *.7z format which offers superior compression ratios to traditional (PKZIP) *.zip files:


    1. 7- zip主页

    7z.exe 的路径添加到您的 PATH 环境变量。请参阅此质量检查:
    如何在Windows中设置路径和环境变量

    Add the path to 7z.exe to your PATH environment variable. See this QA: How to set the path and environment variables in Windows

    打开一个新的命令提示符窗口,并使用此命令创建PKZIP *。zip 文件:

    Open a new command-prompt window and use this command to create a PKZIP *.zip file:

    7z a -tzip {yourfile.zip} {yourfolder}
    




    跨平台Java:



    如果您已经安装了Java JDK,则可以使用 jar 实用程序来创建Zip文件,因为 *。jar 文件是基本上只是重命名了 *。zip (PKZIP)文件:

    Cross-platform Java:

    If you have the Java JDK installed then you can use the jar utility to create Zip files, as *.jar files are essentially just renamed *.zip (PKZIP) files:

    jar -cfM {yourfile.zip} {yourfolder}
    

    说明:
    * -c压缩
    * -f指定文件名
    * -M不包含清单文件

    Explanation: * -c compress * -f specify filename * -M do not include a MANIFEST file

    这篇关于如何使用cmd行压缩文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆