How to zip a file using cmd line?

前端 未结 8 1241
灰色年华
灰色年华 2020-12-14 07:10

I want to zip a directory using bat file command.

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

Like t

相关标签:
8条回答
  • 2020-12-14 07:39

    You can use the following command:

    zip -r nameoffile.zip directory
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-14 07:40

    ZIP FILE via Cross-platform Java without manifest and META-INF folder:

    jar -cMf {yourfile.zip} {yourfolder}
    
    0 讨论(0)
  • 2020-12-14 07:44

    If you are using Ubuntu Linux:

    1. Install zip

      sudo apt-get install zip
      
    2. Zip your folder:

      zip -r {filename.zip} {foldername}
      

    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.

    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. Download 7-Zip from the 7-Zip home page

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

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

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

    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}
    

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

    0 讨论(0)
  • 2020-12-14 07:45

    Not exactly zipping, but you can compact files in Windows with the compact command:

    compact /c /s:<directory or file>
    

    And to uncompress:

    compact /u /s:<directory or file>
    

    NOTE: These commands only mark/unmark files or directories as compressed in the file system. They do not produces any kind of archive (like zip, 7zip, rar, etc.)

    0 讨论(0)
  • 2020-12-14 07:49

    Yes, we can zip and unzip the file/folder using cmd. See the below command and simply you can copy past in cmd and change the directory and file name

    To Zip/Compress File
    powershell Compress-Archive D:\Build\FolderName D:\Build\FolderName.zip

    To Unzip/Expand File
    powershell expand-archive D:\Build\FileName.zip D:\deployments\FileName

    0 讨论(0)
  • 2020-12-14 07:49

    The zip Package should be installed in system.

    To Zip a File

    zip <filename.zip> <file>
    

    Example:

    zip doc.zip doc.txt 
    

    To Unzip a File

    unzip <filename.zip>
    

    Example:

    unzip mydata.zip
    
    0 讨论(0)
提交回复
热议问题