Zip в командной строке windows

In the past it was not possible to create Zip files and Unzip archives in Windows without installing third-party programs like WinZip and 7-Zip.

But now Windows has a built-in capability to Zip files and folders and Unzip archives from the command line using PowerShell.

Starting from Windows 8 with PowerShell 3.0 and .NET Framework 4.5 installed by default, it is possible to use a kind of zip and unzip commands from the command line.

Cool Tip: Download a file using PowerShell! Read more →

Zip/Unzip From The Command Line In Windows

Depending on the version of PowerShell there are different ways to Zip files and folders and Unzip archives in Windows from the command line.

To determine a version of PowerShell on your machine, execute:

PS C:\> $PSVersionTable.PSVersion

PowerShell 5.0 (Windows 10) and greater

Starting from PowerShell 5.0 (Windows 10), it is possible to Zip files and folders and Unzip archives in Windows using Compress-Archive and Expand-Archive PowerShell commands.

Zip a file or a folder from the command line in Windows:

PS C:\> Compress-Archive -Path 'C:\input' -DestinationPath 'C:\output.zip'

Zip all files in a folder:

PS C:\> Compress-Archive -Path 'C:\folder\*' -DestinationPath 'C:\output.zip'

Unzip an archive from the command line in Windows:

PS C:\> Expand-Archive -Path 'C:\input.zip' -DestinationPath 'C:\output'

PowerShell 3.0 (Windows 8) and greater

Starting from PowerShell 3.0 (Windows 8), it is possible to Zip folders and Unzip archives in Windows from the command line using the special methods in PowerShell.

Zip all files in a folder from the command line in Windows:

PS C:\> Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::CreateFromDirectory('C:\folder', 'C:\output.zip')

Unzip an archive from the command line in Windows:

PS C:\> Add-Type -A 'System.IO.Compression.FileSystem';
[IO.Compression.ZipFile]::ExtractToDirectory('C:\input.zip', 'C:\output')

Was it useful? Share this post with the world!

Last Updated :
30 Aug, 2024

One effective technique to handle data without depending on third-party software is to use the Command Prompt (CMD) on Windows to compress and extract files and directories. To use CMD to compress files and directories, you must utilize the integrated 7z command-line tool. If you work with large files on your Windows computer, then you need to know how to extract files and folders using the command prompt on Windows. You can manage your documents using the command prompt in just simple steps.

In this article, we will show you how to use basic command prompt commands to compress or extract files and folders. This method also helps in improving the efficiency of file transfer and also saves disk space. Now, follow the below methods step-by-step to Compress or Extract files and folders using CMD.

How to Compress or Extract files and folders using CMD?

Although it is mainly used for NTFS file compression, Windows comes with an integrated application called Compact that allows you to compress files and folders. On the other hand, Windows 10 and later versions of Windows allow you to use the Compact command to create ZIP files. Here are some straightforward ways to compress and extract files and folders using the Command Prompt on Windows, complete with a step-by-step guide.

Method 1: Using Compact Command

Step 1: To compress files Click ‘Win + R‘, type ‘cmd’ in the open box, and then press Enter.

cmd_3

Step 2: Next, change the directory to the target location using the cd command:

cd C:\Users\YourUsername\Documents

Step 3: After you have navigated to the directory where compression is needed, type the following command to compress a file:

compact /c filename.ext

Replace filename.ext with the name of the file, you want to compress.

image-(2)

To compress an entire folder and its subfolders:

compact /c /s:directoryname

Replace directoryname with the name of the folder you want to compress.

Method 2: Creating a Compressed ZIP File Using Compress Command

Step 1: Open Command Prompt as Administrator.

cmd_4

Step 2: Use the Makecab Command:

First, list all files into a directive file:

dir /b /s *.* > list.txt

Step 3: Then compress the files listed in list.txt:

makecab /f list.txt

How to Extract Files and Folders?

Now, let’s check out two different methods on how to extract any file and folder using the command prompt in no time.

Method 1: Using Expand Command

Step 1: Search for Command Prompt by either clicking on the Start menu or pressing Win + R. Type cmd, and then hit the Enter key.

Step 2: Use Expand Command:

Navigate to the location of your compressed file (.cab), Use the cd command to navigate:

cd C:\Path\To\Your\File

from there, you can make use of Expand Command.

expand filename.cab -F:* C:\DestinationFolder

Replace filename.cab with the name of your compressed file and C:\DestinationFolder with the path where you want the files to be extracted.

Method 2: Extracting ZIP Files using PowerShell

Step 1: To launch PowerShell, type that in the Start menu.

Step 2: Use the cd command to navigate to the location of the file:

cd C:\Path\To\Your\File

Step 3: Extract the ZIP file:

Expand-Archive -Path "C:\path\to\your\file.zip" -DestinationPath "C:\path\to\extract\to"

Replace "C:\path\to\your\file.zip" with the path to your ZIP file and "C:\path\to\extract\to" with the path where you want the files to be extracted.

These methods provide you with basic skills for compression and extraction using Command Prompt and PowerShell for files on Windows.

Conclusion

To put it simply, using the Command Prompt in Windows for file/folder compression or deletion is straightforward and efficient. This strategy is particularly valuable for handling large data sets economically. If you learn just a handful of basic commands like ‘’compact” and ”expand’’, you can reduce volumes of disk space and enhance your file organization. Employing these commands consistently will enhance your expertise and enable you to exploit all the capabilities your Windows system offers.

Also Read

  • How to Unzip Files on Windows and Mac?
  • How to Compress Files in Linux | Tar Command
  • How to compress file in Linux | Compress Command

Sign in to your MUO account

closeup of a screen displaying command prompt

Are you running out of space on your Windows PC? The best thing you can do to free up some space is to compress big files through zipping. There are plenty of third-party tools that can come in handy in this situation.

However, if you prefer to use Command Prompt or Windows PowerShell over anything else, there are commands you can use in these utilities to zip or unzip files. So, let’s check out how to zip or unzip files using Command Prompt and Windows PowerShell.

How to Zip Files Using Command Prompt

You can zip files through Command Prompt using the tar command. It’s a command line tool that helps you to extract files and create archives. However, this command only works in Windows 10 or later.

Here’s how to zip files using Command Prompt:

  1. Open the Start Menu by pressing the Win key.
  2. In the search bar, type Command Prompt and Run as administrator from the right pane.
  3. In the console, type the following command and press Enter. Replace ‘Place’ with the location of the file.

            cd Place
        
    Place of the file

  4. Type dir and press Enter. It’ll show the files inside the selected folder.

    Dir command in CMD

  5. To zip all the files inside the selected folder, type the following command and press Enter. Replace ‘Compressed‘ with the name you want to give your folder where the zip file will be stored. Also, replace ‘FileExt‘ with the extension of the file you’re zipping.

            tar -a -c -f Compressed.zip *.FileExt
        
    Tar command in CMD

  6. To zip a single file, execute the following command. Again, replace ‘Compressed‘ with the name you want to give your folder where the zip file will be stored, ‘FileExt‘ with your file’s extension, and ‘FileName‘ with the name of the file you want to zip.

            tar -a -c -f Compressed.zip FileName.FileExt 
        
    Compressing one file in CMD

How to Zip Files Using Windows PowerShell

There are several viable ways to create zip files on Windows. One of these is through Windows PowerShell. However, the tar command doesn’t work in Windows PowerShell; we’ll use another command to get the work done.

Here’s how to zip files using Windows PowerShell:

  1. Open the Start Menu, type Windows PowerShell, and choose Run as administrator from the right pane.
  2. In the console, type the following command and press Enter. Ensure to replace file destination and target location with the location of the file and the place where you want the file to be zipped, respectively. Also, replace file name with the name of the file you want to zip and destination name with the destination folder name.

            Compress-Archive -LiteralPath 'file destination\file name' -DestinationPath 'target location\destination name'
        
    Zipping command in PowerShell

If you want to zip multiple files, execute the following command. Replace file destination and file destination 1 with the location of the first and second files, respectively. And replace file name and file name 2 with the first and second file names.

        Compress-Archive -LiteralPath 'file destination\file name', 'file destination 1\file name 2 -DestinationPath 'target location\destination name'
Zipping 2 files at once

How to Unzip Files Using Command Prompt

There may be situations where you want to unzip files on your Windows computer. Fortunately, you can do that as well using Command Prompt. Here’s how:

  1. Launch Command Prompt with admin privileges.
  2. Use the cd command to head toward the zip file’s location.
  3. Type the following command and press Enter. Replace ‘Name‘ with the name of the zip file.

            tar -xf Name.zip
        
    Unzipping file in CMD

You’ve successfully unzipped the file.

How to Unzip Files Using Windows PowerShell

Windows PowerShell lets you quickly unzip files on your computer. Here’s how to do that:

  1. Open Windows PowerShell with admin rights.
  2. Type the following command and press Enter. Make sure to replace <file destination> and <target location> with the location of the zip file and the place where you want the file to be unzipped, respectively.

            Expand-Archive -LiteralPath <file destination> -DestinationPath <target location>
        
    Unzipping file in PowerShell

Save Up Space on Windows 11 by Zipping Your Files

As a Windows user, you will always come across situations where you want to zip or unzip files. However, if you don’t want to use a third-party tool, you can use Command Prompt and Windows PowerShell to quickly zip and unzip files on Windows using the above methods.

Meanwhile, you might be interested in learning a few important Command Prompt commands.

Comprehensive Tutorial on Zipping in Windows Command Line 📦

In today’s fast-paced digital world, managing your files efficiently is a must. Whether you need to compress a single file, multiple files, or an entire directory, using the Windows command line can be a powerful way to get the job done quickly. This guide walks you through how to zip in Windows command line, including zipping files, folders, and directories. We’ll also recommend the popular tool 7-Zip for those who want more advanced features.

1. Using PowerShell’s Compress-Archive Command 🛠️

For Windows 10 and later, PowerShell includes a built-in command called Compress-Archive. This command allows you to zip files and folders without needing third-party software.

a. Zip a Single File

To zip a single file, open PowerShell and run:

Compress-Archive -Path "C:\Path\To\YourFile.txt" -DestinationPath "C:\Path\To\Archive.zip"

This command takes YourFile.txt and compresses it into Archive.zip.

b. Zip Multiple Files

To zip multiple files, list them using a comma-separated array:

Compress-Archive -Path "C:\Path\To\File1.txt", "C:\Path\To\File2.txt" -DestinationPath "C:\Path\To\FilesArchive.zip"

c. Zip a Folder or Directory

Compressing an entire folder is just as simple:

Compress-Archive -Path "C:\Path\To\YourFolder" -DestinationPath "C:\Path\To\FolderArchive.zip"

This command zips the entire contents of YourFolder into FolderArchive.zip.

2. Using 7-Zip from the Command Line 🔧

For those who require additional compression options or support for various archive formats, 7-Zip is a top recommendation. 7-Zip is a free, open-source file archiver with high compression ratios and a powerful command-line interface.

a. Installing 7-Zip

  • Download 7-Zip from the official website.
  • Install it on your system (default installation path is usually C:\Program Files\7-Zip\7z.exe).

b. Using 7-Zip to Zip Files and Folders

Open the Command Prompt and navigate to the directory containing the files or folders you wish to zip. Here are some common commands:

  • Zip a Single File:

cmd
"C:\Program Files\7-Zip\7z.exe" a -tzip Archive.zip "YourFile.txt"

  • Zip Multiple Files:

cmd
"C:\Program Files\7-Zip\7z.exe" a -tzip FilesArchive.zip "File1.txt" "File2.txt"

  • Zip an Entire Folder:

cmd
"C:\Program Files\7-Zip\7z.exe" a -tzip FolderArchive.zip "YourFolder\*"

Explanation of the Command Options:

  • a : Add files to archive
  • -tzip : Specify the archive type (ZIP in this case)
  • Archive.zip : The name of the output archive
  • "YourFolder\*" : Includes all files within the folder

3. Comparison Table: PowerShell vs. 7-Zip

Feature PowerShell Compress-Archive 7-Zip Command Line
Ease of Use ✅ Very Easy ✅ Easy with more options
Built-In ✅ Included in Windows 10+ ❌ Requires separate installation
Supported Formats ❌ ZIP only ✅ ZIP, 7z, TAR, GZIP, etc.
Advanced Options ❌ Limited ✅ Extensive (encryption, splits, etc.)

Table Note: The check icons (✅) indicate the strengths of each method, so choose the one that best fits your needs.

4. Best Practices and Tips for Zipping Files

  • Always Verify Paths: Ensure that the file or directory paths are correct to avoid errors.
  • Use Meaningful Archive Names: This helps in keeping your files organized and easily identifiable.
  • Test the Archive: After compression, try extracting the archive to ensure that all files are intact.
  • Automate with Scripts: Consider writing batch scripts or PowerShell scripts to automate regular archiving tasks.

Final Thoughts 🎯

Whether you choose the simplicity of PowerShell’s Compress-Archive or the powerful features of 7-Zip, zipping files and folders via the Windows command line is a valuable skill for efficient file management. Experiment with both methods to see which works best for your workflow, and enjoy the flexibility that command line tools bring to your daily tasks.

Happy zipping, and may your archives always be compact and secure! 🚀

  • Home
  • News
  • How to Create Zip Files Using Command Prompt?

By Andrea | Follow |
Last Updated

Are files too large to transfer? Not enough disk space? Regardless of the reasons, creating zip files is common in computer use. This MiniTool post will show you how to create zip files using Command Prompt and give several ways to unzip files. Let’s keep reading.

Command Prompt is officially called the Windows Command Processor, short for CMD. It is the command line interface for Windows operating systems. You can perform various command lines via this tool to fix problems or complete operations.How to open Command Prompt

  • Press Win + S, type Command Prompt into the search bar, and hit Enter to open it.
  • Press Win + R, type cmd into the text box, and hit Enter to open it.

Turn to this post to find more methods about how to open Command Prompt.

How to Create Files Using Command Prompt

Command lines are widely used to resolve many computer errors. You can also zip files with Command Prompt by using the tar command line. Please follow the next steps to learn how to do it.Step 1: Press Win + R to open the Run window.Step 2: Type cmd into the text box and press Shift + Ctrl + Enter simultaneously to run Command Prompt as administrator.Step 3: Type the command line: cd Location and hit Enter.Please replace Location with the specific location of the folder you want to zip up.

choose the folder to zip

Step 4: Type dir and hit Enter. Then the files included in the selected folder will display in the interface.

display the files

Step 5: Type the command line: tar -a -c -f Compressed.zip *.FileExt and hit Enter.If you want to compress all the files in the folder, please replace Compressed with the name of the zip folder and change FileExt to the extension(s) of the file you’re going to compress.

Tips:

If there are different types of files, you can add more *.FileExt at the end of the command line. For example, tar -a -c -f Pictures.zip *.png *.docm.

compress all the files

If you just want to zip a single file, please replace * with the name of the file you want to zip and change Compressed and FileExt to the same as in the first situation.

zip a single file

You can find the created zip folders in the original folder.

How to Zip Files Using Other Methods

In addition to creating a zip file using Command Prompt, there are many other methods to help you zip files.Method 1: Zip files by Send toStep 1: Right-click on the folder you want to compress.Step 2: Choose Send to > Compressed (zipped) folder.

compress a folder use Send to

The new zip folder will be created under the same name and the same location.Method 2: Compress files with File ExplorerStep 1: Locate the folder you want to zip in File Explorer.Step 2: Shift to the Share tab on the toolbar.Step 3: Choose Zip to compress the folder.

compress files with File Explorer

You can change the name of the created zip folder directly.

How to Unzip Files

If you want to extract files from a zip folder, you can also use Command Prompt to make it.Step 1: Press Win + S and type Command Prompt into the search bar.Step 2: Choose Run as administrator from the right panel.Step 3: Type cd Location and hit Enter.Please replace Location with the specific path of the file.Step 4: Type tar -xf Name.zip and hit Enter. Change Name to the name of the zip folder.

unzip a folder

Then, you can find the uncompressed files in the same folder.

Bottom Line

You will face various situations that need to zip files. You can try to create zip files using Command Prompt if you don’t want to install third-party tools.If you delete files accidentally in the process of zipping files, you can try MiniTool Power Data Recovery to restore them.

MiniTool Power Data Recovery FreeClick to Download100%Clean & Safe

This free data recovery tool allows you to rescue various types of files like photos, videos, archives, documents, etc. You can also recover files from external hard drives, SD cards, memory cards, and so on. You can use the free edition to recover up to 1GB of files. If needed, you can get the full edition to obtain unlimited data recovery capacity.

About The Author

Position: Columnist

Andrea graduated in English and has a keen interest in the IT industry and questions that arise when computers are used. She is passionate about new things and challenging things and has a wide range of interests like playing guitar, gaming, and crafting.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Amd radeon windows server 2008 r2
  • Не удается установить приложение windows phone
  • Download free games for windows games
  • Программа для кастомизации панели задач windows 10
  • Пропала папка appdata на windows 10