How to Compress and Decompress Files with Commands in Windows

Last update: 10/09/2025
Author Isaac
  • Compact and tar allow you to compress and extract from CMD en Windows with fine control of parameters.
  • Windows 11 Expands native format support; for encrypted archives, use 7-Zip or WinRAR.
  • Alternatives: 7-Zip, PeaZip, WinRAR, WinZip and online services for converting or extracting.

Compress and decompress with commands in Windows

When you work with a lot of files, mastering the Windows command line for compressing and extracting files saves you time and clicks. In addition, it allows you to automate repetitive tasks with scripts that work the same every time and on any computer in your environment.

In this completely practical guide we gather everything you need: the native compact command, the use of tar in the Symbol of the system, options in Windows 10 and Windows 11, an example of script with WinZip, utilities like 7-Zip or PeaZip And, if you need it, online services to get you through. All explained with usage examples and key parameters.

Access the command line in Windows 10 and Windows 11

In Windows 10 you can quickly open the console by pressing the Start button and searching for “Command Prompt” or “CMD”; When you run it you will see the interpreter of commands clever to receive orders.

In Windows 11, it's very convenient to right-click the Start button and choose Command Prompt/Terminal/PowerShell. With that you get a prepared window to enter the commands you will see below.

compact: compress and decompress NTFS files from CMD

The compact command works with compression at the file level. NTFS file system. It is ideal for reducing disk size existing files and folders without creating .zip or .tar files. It allows you to act on directories, subdirectories, and patterns.

Compress the contents of a specific folder

Let's say you save images in Documents\Photos. It's common to put them first in the path to simplify things. For example, navigate with cd and runs:

cd Documents
compact /c /s:fotos

Here we use two modifiers: /c (compress) y /s:directory (recursive)The process will list each item it compresses. If the summary shows 13 items but you only see 12 lines, don't be alarmed: the folder itself counts as an item; additionally, the total may include files in the parent directory and in subfolders.

Compress only some files using wildcards

If you are interested in a subset, you can apply a pattern. For example, for files whose name ends in 1 inside photos:

compact /c /s:fotos *1.jpg

When finished, you'll see that only matching files have been marked as compressed. It will be reflected in File Explorer using the compression information icon NTFS.

Compress only the current folder (no subdirectories)

If you don't want to traverse subfolders, move to the destination folder and run compact without the /s switch. For example, go into photos and applies:

cd fotos
compact /c

You can also match patterns within the current directory: to affect specific files without touching the rest:

compact /c *1.jpg

Unzip with compact

To reverse NTFS compression use /u (uncompress). Recursively unzip photos it would look like this:

compact /u /s:fotos

The result will show you how many files and directories have been processed. Remember that the root directory is also counted. even if it does not appear as an independent line.

  The camera cannot establish connection

tar on Windows: Working with .tar, .tar.gz, .tgz, and .gz from CMD

Windows includes tar on the command line, so you can create and extract tarballs without installing anything extra. It is perfect for packaging entire directories or manage files from environments UNIX.

Compress (create) a .tar.gz file

To create a gzipped archive (tar.gz) containing a file or folder, use -c (create), -z (gzip), -v (verbose), and -f (file): This combination is very common.

tar -czvf archivo_comprimido.tar.gz archivo_o_directorio

For example, to compress document.txt: will generate compressed_document.tar.gz with the packaged content.

tar -czvf documento_comprimido.tar.gz documento.txt

Unzip (extract) a .tar.gz

To extract, replace -c with -x (extract) and keep -zvf to recognize gzip and show progress. The -f option indicates the source file:

tar -xzvf archivo_comprimido.tar.gz

You can also specify destination with -C: make sure the folder exists to avoid errors like "tar: could not chdir to 'C:\path'".

tar -xvzf C:\prueba.tar -C C:\prueba

Native format support in Windows 11

Windows 11 has expanded archive format support: you can work with .tar, .7-zip, .rar, and .gz files from the system, with more comprehensive context menus. This reduces the need to install external utilities. for basic tasks. In recent versions (24H2), it is also indicated that the operations on encrypted files are not supported: if the file is protected, use 7-Zip or WinRAR.

From the context menu, users can zip and unzip files from Explorer with a couple of clicks. It is a clear improvement in user experience, although if you need automation or advanced flows, the command line is still the most flexible option.

Batch script with WinZip (wzzip.exe)

If you have WinZip installed, you can automate compressions with a BAT file. The following example defines variables and calls wzzip with parameters to add recursively:

@echo off
set ZIP_EXE="C:\Program Files\WinZip\wzzip.exe"
set ARCHIVO_ZIP="nombre_deseado.zip"
set CARPETA_A_COMPRIMIR="C:\ruta\a\tu\carpeta"
"%ZIP_EXE%" -a -r "%ARCHIVO_ZIP%" "%CARPETA_A_COMPRIMIR%"

What each part does: @echo off clears the output; ZIP_EXE sets the path to the executable; ZIP_FILE sets the name of the ZIP; FOLDER_TO_ZIP defines which folder to pack; the final call runs WinZip with -a (add/create) y -r (recursive) to include subdirectories.

  Timeshift Tutorial for Linux: A Complete Guide to Mastering It

Third-party tools on Windows (GUI and CLI)

Although this guide focuses on the console, it is useful to know about additional compressed file managers. They can get you out of trouble with less common formats or large files.

PeaZip

PeaZip supports nearly 200 formats and allows you to create .tar, .gz, and .tar.gz among many others. To compress open PeaZip and add the files from the program or by right-clicking in Explorer. Then, choose GZip if you want to archive tar.gz or TAR without compression; confirm with OK.

To extract, right-click on the file and choose PeaZip > Extract here, or use Extract… to extract the file. select a specific routeYou can also open the file as a container to view its contents before extracting.

7-Zip

To unzip, right-click > 7-Zip > Extract Here, or Extract Files… to define the destination. It also allows you to open as a file to inspect the contents before removing.

WinRAR

WinRAR handles RAR, ZIP, CAB, ARJ, LZH, TAR, GZ, UUE, BZ2, JAR, ISO, Z and 7Z, among others. From Options > Settings > Integration You can associate extensions. To extract, right-click > Extract files and choose the location. It offers encryption, configurable compression level, and volume splitting. Remember that It is shareware with a 40-day trial.

WinZip

WinZip also works with .tar, .tar.gz, .tgz, and .gz. You can extract by right-clicking and choosing "Unzip to..." or open the file with WinZip and use the side panel to open the file. define the destination folder. It's a classic and simple option for users who already have it installed.

B1 Free Archiver

Compatible with B1, ZIP, JAR, XPI, RAR, 7Z, ARJ, BZ2, CAB, DEB, GZIP, TGZ, ISO, LZH, LHA, LZMA, RPM, XAR, DMG and more. Works on Windows, Linux and macOS, supports protected files and offers AES-256 encryption. It's completely free and can be downloaded from its website.

ZIP and UNZIP in Terminal (Linux/WSL) and Practical Uses

Work with ZIP via command line It is cross-platform: if you use WSL on Windows, or work on Linux, you can install zip and unzip from the package manager. In Debian/Ubuntu:

sudo apt-get install zip
# o
sudo apt install zip

On distributions with yum, it is just as easy to install: with administrator privileges or sudo depending on your configuration:

sudo yum install zip

Compress with zip

To compress a single file: will create destination.zip with the file inside:

zip ARCHIVO_COMPRIMIDO_DESTINO.zip ARCHIVO_A_COMPRIMIR

Typical examples for folders: add -r for recursive compression of subdirectories. In the current directory:

zip -r destino.zip

Or pointing to a specific folder: useful for packaging complete projects:

zip -r destino.zip directorio_a_comprimir

If you need more control, zip supports options like -q (quiet), -e (encrypt), -u (update) or -m (move, deleting the original when adding it). To not compress (only archive), there is the level -0 (zero compression).

  Windows 11: The bug that turns videos and games red and how to fix it

Unzip

The basic extraction is direct: unzips into the current directory:

unzip archivo.zip

To view the content without extracting: list of files, size and dates:

unzip -l archivo.zip

To extract to another path, add -d: create the structure in the chosen folder:

unzip archivo.zip -d /ruta/a/destino

Or extract only a specific file from the ZIP: ideal for recovering a single resource:

unzip archivo.zip file1.txt

More about tar and gzip: useful options

tar supports several compression engines in addition to gzip. Combine -f with other options to create, list or extract as needed.

Create a simple tar (without compression): packs multiple files in a single container:

tar -cvf archivo.tar archivo1 archivo2

Create with gzip (tar.gz or tgz) from a directory: You will see each file as it is processed:

tar -czvf archivo.tar.gz directorio/

Extract a tar without compression: leave the files in the current folder:

tar -xvf archivo.tar

List the contents of an unextracted tarball: useful to inspect before acting:

tar -tvf archivo.tar

Other engines: -j (bzip2) generates .tar.bz2 y -J (xz) generates .tar.xz, choosing the balance between compression level and speed.

gzip for loose files

gzip compresses individual files and replaces the original with name.gz. To preserve the original add -k:

gzip ejemplo.txt      # produce ejemplo.txt.gz
gzip -k ejemplo.txt  # conserva ejemplo.txt

To unzip: use the -do gunzip command equivalent:

gzip -d ejemplo.txt.gz
# o
gunzip ejemplo.txt.gz

You can also compress several at once or redirect the output with -c: useful in pipelines:

gzip archivo1.txt archivo2.txt archivo3.txt
gzip -c archivo.txt > archivo.txt.gz

Controls the performance balance with -9 (maximum compression) or leave the default value. For entire directories, combine gzip with tar as seen in the previous examples.

zip
Related article:
How to unzip ZIP files from the command line in Windows step by step