Zip and Unzip files and folders from command line in windows
This tutorial shows you how to zip and unzip files in Windows OS.
Linux has default inbuilt tools to zip and unzip files.
How to zip and unzip files and folders in the command line Windows
There are multiple ways we can zip files or folders.
- using jar command
Jar command is available with java installation on Windows.
Follow is a command to zip a file or folder using jar command
jar -cMf target.zip sourceFolder
files under the source folder are compressed and created as target.zip file Options: -c: zip files from a source folder -v: Verbose output displayed to console -f: zip file name Follow the command used to unzip a file and extract the contents
jar -xvf target.zip
test.zip is located under the current running directory. Furthermore, It extracts all files and folders into a name directory of a filename.
Options: -x: Unzip files from a zip file -v: Verbose output displayed to console -f: zip file name
-
using compress
-
compact tool compact🔗 is an executable tool for the compression of files. It is the default compression in Window
compact options
How to zip and unzip a file in PowerShell windows
Windows provides the following command line tools in PowerShell - Compress-Archive: Compress the files in zip file format - Expand-Archive: Unzip the zip file and extracts it to the current folder.
- Open Windows PowerShell Terminal
- Run the below command to zip the file
Compress-Archive test.txt final.zip
- To unzip the file,
Expand-Archive final.zip
Conclusion
Learned how to zip and unzip files and folders from a command line and PowerShell.