Last updated:

Quick answer: on Windows 10 (build 17063 and later) and Windows 11, create a zip from Command Prompt or PowerShell with tar -a -c -f archive.zip file.txt and extract it with tar -x -f archive.zip. The -a flag matters: without it, tar writes a tar archive and only names it .zip. In PowerShell you can also use Compress-Archive and Expand-Archive.

tar -a -c -f archive.zip file.txt
tar -x -f archive.zip

Windows has no built-in zip or unzip command in Command Prompt, so the choice is between three tools. The table shows which one fits which job.

ToolWorks inBest forCreate a zipExtract
tar (bsdtar)CMD and PowerShellQuick zips with nothing to install; also reads .tar.gz, .7z and moretar -a -c -f out.zip filestar -x -f out.zip
Compress-Archive / Expand-ArchivePowerShell onlyScripts; control over compression level and overwriteCompress-Archive -Path files -DestinationPath out.zipExpand-Archive -Path out.zip -DestinationPath folder
7z (7-Zip)CMD and PowerShell after installPasswords, .7z, huge or unusual archives7z a -tzip out.zip files7z x out.zip

Commands on this page were checked as follows: the tar and 7z commands were run with bsdtar 3.7.2 and 7-Zip 23.01 on Ubuntu 24.04. The tar.exe that ships with Windows is built from the same libarchive project (Microsoft says it is based on bsdtar), but I did not run it on a Windows machine for this update. The PowerShell parameters come from Microsoft Learn and were not run today. The screenshots were taken on Windows in February 2024.

Zip and unzip with tar

Microsoft added tar to Windows 10 in Insider build 17063, and it is based on bsdtar from the libarchive project. Run tar --version to confirm it is there. Open the folder that holds your files first:

cd C:\Users\Ali\Documents
dir
Command Prompt showing cd C:\Users\Ali\Documents followed by dir, listing PDF and text files before zipping
Starting folder: cd into the folder, then dir to see the files.

Create a zip file with tar -a

tar -a -c -f files.zip file.txt

-a (auto-compress) picks the archive format from the file extension, -c creates, and -f names the output. To zip several files or a whole folder, list them after the name:

tar -a -c -f archive.zip file.txt b.txt
tar -a -c -f docs.zip docs

Folders are added with everything inside them. In my test the folder case listed docs/ and docs/x.txt inside the archive.

Common mistake: tar -c -f files.zip file.txt (without -a) does not create a zip. In my bsdtar 3.7.2 test it produced a POSIX tar archive named files.zip, and an empty file came out at 1,536 bytes, against 198 bytes with -a. The screenshot below shows that 1,536-byte size on Windows. Tools such as Explorer or an email filter may not open that file as a zip. Always add -a.

Command Prompt running tar -c -f files.zip file.txt, then dir showing files.zip at 1,536 bytes next to Tar.zip and ZipFileName.zip
Screenshot from Windows (Feb 2024) of the command without -a. The 1,536-byte files.zip is the size of a tar archive holding an empty file; the same command with -a gives a real zip.

Unzip with tar

tar -x -f files.zip
dir

-x extracts. You do not need -a here because tar detects the format itself. To extract into another folder, the folder has to exist already:

mkdir C:\Users\Ali\extracted
tar -x -f files.zip -C C:\Users\Ali\extracted

In my test, -C pointing to a folder that did not exist stopped with could not chdir. To only look inside an archive, run tar -tf files.zip (add v for sizes and dates).

Command Prompt running tar -xf files.zip and then dir to show the extracted files in the folder
Extracting with tar -xf and checking the folder with dir.
Advertisement

Zip and unzip with PowerShell

PowerShell has two cmdlets for this. They work in Windows PowerShell and in PowerShell 7, but not in Command Prompt.

Compress-Archive -Path C:\Users\Ali\Documents -DestinationPath C:\Archives\Draft.zip -CompressionLevel Fastest
Windows PowerShell running Compress-Archive with Path, CompressionLevel Fastest and DestinationPath C:\Archives\Draft.zip using a splatted hashtable
The same command written as a hashtable (splatting), the way the original screenshot shows it.
dir C:\Archives
PowerShell dir C:\Archives output listing Draft.zip with a length of 112550 bytes
Draft.zip exists in C:\Archives after the command.
Expand-Archive -Path C:\Archives\Draft.zip -DestinationPath C:\Users\Ali\Documents
Windows PowerShell running Expand-Archive with Path C:\Archives\Draft.zip and DestinationPath C:\Users\Ali\Documents
Extracting Draft.zip back into the Documents folder.

Details from the Microsoft Learn pages for Compress-Archive and Expand-Archive that cause most surprises:

BehaviorWhat to know
Folder path vs wildcard-Path C:\Reference includes the folder itself in the zip. -Path C:\Reference\* zips its contents without the top folder.
Compression levelOptimal (default), Fastest or NoCompression.
Existing archive-Force overwrites it. -Update replaces older same-named files and can add files to the existing zip. The two cannot be combined.
Missing .zip extensionIf the destination name has no .zip extension, the cmdlet adds it.
Hidden filesHidden files and folders are ignored when creating or updating the archive.
2 GB limitBoth cmdlets use the ZipArchive API, which limits the maximum file size to 2 GB. Use 7-Zip for larger files.
Expand-Archive overwriteExisting files are not overwritten unless you add -Force. A missing destination folder is created.

Zip and unzip with 7-Zip

7-Zip is useful for password-protected archives, the .7z format and very large files. Install it from 7-zip.org, or with Chocolatey if you already use it:

Stuck at this step? Ask us, it is free and include the exact error.

choco install 7zip.install -y
PowerShell running choco install 7zip.install -y, with Chocolatey reporting that 7-Zip installed successfully
Installing 7-Zip with Chocolatey (screenshot from Windows, Feb 2024).

If 7z is not recognized afterwards, open a new terminal window so the updated PATH loads, or run it with its full path in C:\Program Files\7-Zip.

The original version of this guide used -t7z, which creates a .7z file, not a zip. For a real zip use -tzip:

7z a -tzip files.zip *.txt
7z a -t7z files.7z *.txt
Command Prompt running 7z a -t7z files.7z *.txt, with 7-Zip output ending in Everything is Ok
Creating files.7z with 7-Zip. Use -tzip instead if you need a .zip.

To extract, x keeps the folder structure and e puts every file into one flat folder. In my test of a zip containing docs/x.txt, 7z x restored docs\x.txt and 7z e placed x.txt directly in the output folder. Use -o (no space) to choose the folder:

7z x files.zip -oC:\Users\Ali\extracted
7z l files.zip

7z l lists the contents without extracting.

Command Prompt running 7z e files.7z, with 7-Zip output listing Files: 3 and Everything is Ok
Extracting files.7z with 7z e in the current folder.

Verify the archive

Before you delete the originals or send the zip, list what is inside. Both of these commands only read the file:

tar -tf archive.zip
7z l archive.zip

The names you expect should appear. For Linux archives, see the guide to extracting .tar.gz files with tar. To read an extracted text file straight from the terminal, use the cat command in Windows. If the archive holds sensitive material, the cipher command in Windows can also wipe the leftover copies.

Advertisement

Troubleshooting

ProblemLikely causeFix
tar is not recognizedWindows older than Windows 10 build 17063Update Windows, or use 7-Zip.
The .zip made with tar will not open in Explorer or another toolCreated without -a, so it is a tar archiveRecreate it with tar -a -c -f name.zip files.
could not chdir when using -CThe target folder does not existCreate it with mkdir first.
Files are missing from a Compress-Archive zipHidden files are skippedUse 7-Zip or tar -a -c if hidden files must be included.
Expand-Archive leaves old files unchangedExisting files are not overwritten by defaultAdd -Force.
Compress-Archive fails on a very large file2 GB file-size limitUse 7z a -tzip or tar -a -c -f.
7z is not recognized7-Zip is not on PATH in this windowOpen a new terminal, or run it from C:\Program Files\7-Zip.

Frequently asked questions

Is there a zip command in Windows Command Prompt?

No. Command Prompt has no zip or unzip command. Use tar -a -c -f, PowerShell’s Compress-Archive, or 7-Zip.

Does tar on Windows create a real .zip file?

Yes, but only with -a. Without it, my bsdtar test produced a tar archive that merely had a .zip name.

How do I unzip to a specific folder?

With tar use -C folder (the folder must exist), with PowerShell use -DestinationPath folder, and with 7-Zip use -ofolder.

Advertisement