Windows CMD Zip Command: How to Compress Files
In this article
Windows CMD does not include a native zip command. The built-in tar command (available in Windows 10 and 11) can create .zip archives, so you can compress files from the Command Prompt without installing anything extra. The basic syntax is tar -a -c -f archive.zip folder_or_file. This guide shows you exactly how to use it, plus what to do if you need more advanced options.
What You'll Need
- A PC running Windows 10 or Windows 11 (the
tarcommand is included by default). - Access to Command Prompt (no admin rights required for most operations).
- The files or folders you want to compress, and enough free disk space for the resulting archive.
Step-by-Step
- Open Command Prompt. Press
Win + R, typecmd, and press Enter. Alternatively, search for “Command Prompt” in the Start menu and click it. A black window opens with a prompt showing your current directory. - Navigate to the folder containing your files. Use the
cdcommand. For example, to go to your Documents folder, typecd %USERPROFILE%\Documentsand press Enter. You can also typecd /d D:\Projectsto switch drives. The prompt updates to show the new path. - Decide on the archive name and location. You will specify the full path or just a filename (which will be created in the current directory). For example,
backup.zipwill be created in the current folder. - Run the tar command to create a zip file. The syntax is:
tar -a -c -f archive.zip source
Replacearchive.zipwith your desired name (the.zipextension is required for the-aflag to select zip format). Replacesourcewith the file or folder you want to compress. For example, to zip a folder named “Reports”, type:tar -a -c -f reports.zip Reports
Press Enter. The command runs silently; when the prompt returns, the zip file is ready. - Verify the archive was created. Type
dirand press Enter to list files. You should see your new .zip file with a size greater than zero. To check its contents without extracting, use:tar -tf reports.zip
This lists the files inside the archive. - Extract a zip file (optional). To unzip an existing archive into the current folder, use:
tar -xf archive.zip
Add-Cfollowed by a path to extract to a different folder, e.g.,tar -xf archive.zip -C C:\Temp. - Zip multiple items at once. You can list several sources separated by spaces:
tar -a -c -f combined.zip file1.txt file2.txt folder1
All items are added to the archive with their relative paths. - Use absolute paths if needed. If you are not in the parent folder of the items, provide full paths. For example:
tar -a -c -f C:\Backups\project.zip C:\Work\Project
This creates the zip in C:\Backups and includes the Project folder.
Note: Menu labels and command availability can differ slightly by Windows version or region. The tar command is present in Windows 10 build 17063 and later, and in all Windows 11 versions.
Common Mistakes
- Forgetting the
-aflag. Without-a,tarcreates a .tar file even if you name it .zip. Always include-awhen you want a zip archive. - Using the wrong extension. The archive name must end in
.zipfor the-aflag to produce a zip file. Other extensions like.tar.gzwill create a gzipped tar, not a zip. - Omitting the
-fflag or putting it last. The-fflag must be followed immediately by the archive filename. The order-f archive.zipis correct;archive.zip -fis not. - Spaces in file or folder names. If a path contains spaces, enclose it in double quotes:
tar -a -c -f "my backup.zip" "My Folder". - Assuming
zipworks. Typingzipin Command Prompt returns “'zip' is not recognized”. Usetarinstead, or install a third-party tool like 7-Zip and use its command-line utility. - Not checking permissions. If you get “Access is denied”, you may need to run Command Prompt as administrator or choose a destination folder where you have write access.
Tips
- Use
tar --helpto see all available options for your Windows version. - To exclude files,
tarsupports--exclude=PATTERN. For example,tar -a -c -f backup.zip folder --exclude=*.tmpskips temporary files. - You can compress an entire drive or large folder, but be mindful of free space and time. Zip archives are not encrypted by default; for sensitive data, use a dedicated archiving tool with password support.
- If you frequently zip files, create a batch file (.bat) with your common
tarcommands to save typing. - For scripting,
tarreturns an exit code (0 for success). You can check it withif %errorlevel% neq 0 echo Failed.
Troubleshooting
- “tar is not recognized” – Your Windows version may be too old (pre-17063). Update Windows, or use PowerShell's
Compress-Archivecmdlet instead:Compress-Archive -Path C:\Folder -DestinationPath C:\archive.zip. - “Access is denied” – Run Command Prompt as administrator (right-click > Run as administrator) or ensure you have write permissions to the destination folder.
- Archive is empty or missing files – Check that the source path is correct. Use
dirto confirm the files exist. If using relative paths, make sure you are in the right directory. - “Cannot open file” or “No such file or directory” – The destination path may not exist. Create the folder first with
mkdir, or use a path that already exists. - Zip file is corrupt or won't open – Re-run the command. If the problem persists, try extracting with
tar -xfto see if the archive is valid. If not, the source files may have been in use; close any programs using them and retry. - Command hangs or takes very long – Large folders with many files can take time. Avoid zipping system folders or files in use. Press
Ctrl+Cto cancel if needed.
Frequently Asked Questions
Can I use the zip command in Windows CMD?
No, Windows does not include a native zip command. Use the built-in tar command with the -a flag to create .zip files, or install a third-party tool like 7-Zip and use its command-line executable.
How do I zip a folder and all its contents?
Use tar -a -c -f archive.zip foldername. This includes the folder and everything inside it, preserving the directory structure.
Can I password-protect a zip file with tar?
No, the tar command does not support encryption or password protection. You will need a third-party archiving tool that offers this feature.
What is the difference between tar and zip?
tar is a tape archive tool that can create and extract various archive formats, including .zip when used with the -a flag. zip is a separate utility not included in Windows. Both produce .zip files, but tar is built into modern Windows.
Can I zip files on a network drive?
Yes, as long as you have read access to the source and write access to the destination. Use UNC paths like \\server\share\file.zip if needed, and enclose paths with spaces in quotes.
Is there a size limit for zip files created with tar?
The zip format itself supports large archives, but practical limits depend on your file system (FAT32 has a 4GB limit per file) and available disk space. NTFS and exFAT do not have the same 4GB restriction.