Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Windows CMD Zip Command: How to Compress Files

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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 tar command 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

  1. Open Command Prompt. Press Win + R, type cmd, 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.
  2. Navigate to the folder containing your files. Use the cd command. For example, to go to your Documents folder, type cd %USERPROFILE%\Documents and press Enter. You can also type cd /d D:\Projects to switch drives. The prompt updates to show the new path.
  3. 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.zip will be created in the current folder.
  4. Run the tar command to create a zip file. The syntax is:
    tar -a -c -f archive.zip source
    Replace archive.zip with your desired name (the .zip extension is required for the -a flag to select zip format). Replace source with 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.
  5. Verify the archive was created. Type dir and 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.
  6. Extract a zip file (optional). To unzip an existing archive into the current folder, use:
    tar -xf archive.zip
    Add -C followed by a path to extract to a different folder, e.g., tar -xf archive.zip -C C:\Temp.
  7. 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.
  8. 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 -a flag. Without -a, tar creates a .tar file even if you name it .zip. Always include -a when you want a zip archive.
  • Using the wrong extension. The archive name must end in .zip for the -a flag to produce a zip file. Other extensions like .tar.gz will create a gzipped tar, not a zip.
  • Omitting the -f flag or putting it last. The -f flag must be followed immediately by the archive filename. The order -f archive.zip is correct; archive.zip -f is 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 zip works. Typing zip in Command Prompt returns “'zip' is not recognized”. Use tar instead, 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 --help to see all available options for your Windows version.
  • To exclude files, tar supports --exclude=PATTERN. For example, tar -a -c -f backup.zip folder --exclude=*.tmp skips 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 tar commands to save typing.
  • For scripting, tar returns an exit code (0 for success). You can check it with if %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-Archive cmdlet 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 dir to 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 -xf to 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+C to 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.