Zip and Unzip files and folders from terminal and powershell in windows

Linux has built-in tools for zipping and unzipping files, while Windows offers various user interface tools for the same purpose. This tutorial focuses on demonstrating how to zip and unzip files in the Windows Command Line.

How to Zip and Unzip Files and Folders in the Windows Command Line

There are multiple ways to zip files or folders:

  • Using the jar command

The jar command is available with Java installation on Windows.

Below is a command to zip a file or folder using the jar command:

jar -cMf target.zip sourceFolder

This command compresses files under the source folder and creates the target.zip file.

Options:

  • -c: Zip files from a source folder
  • -v: Display verbose output to the console
  • -f: Specify the zip file name

To unzip a file and extract its contents, use the following command:

jar -xvf target.zip

The target.zip file is located under the current running directory. Furthermore, it extracts all files and folders into a directory named after the filename.

Options:

  • -x: Unzip files from a zip file

  • -v: Display verbose output to the console

  • -f: Specify the zip file name

  • using compact tool The compact🔗 tool is an executable tool for file compression, serving as the default compression tool in Windows.

compact  options

How to Zip and Unzip a File in PowerShell on Windows

Windows provides the following command line tools in PowerShell:

  • Compress-Archive: Compress files in zip file format
  • Expand-Archive: Unzip the zip file and extract it to the current folder.

To zip a file using PowerShell, open the Windows PowerShell Terminal and run the following command.

Compress-Archive test.txt final.zip

To unzip the file, use the command

  Expand-Archive final.zip

Conclusion

This tutorial covers how to zip and unzip files and folders from the command line and PowerShell.