In today’s fast-paced world, time is key and when it comes to sharing files over the internet, you can get irritated because you have to wait. But what if I tell you that you can reduce the size of your files without compromising their integrity? Yes! You can do it using the “Zipping” method.

The “Zipping” method refers to creating the compressed files in the “.zip” format. In Windows, you can utilize multiple methods to create a “.zip” file with reduced size to save disk space and bandwidth while sharing. 

Today’s guide explores the methods to “Zip” or “Unzip” files using the Windows Command Line.

Content Overview

By following this guide, you will learn:

Let’s dive into the details of the above.

Zip and Unzip Files Via the Command Prompt

For zipping and unzipping files via the Command Prompt, follow these approaches:

  • The “tar” Command
  • The “7zip” Utility

Zip and Unzip Files Using the “tar” Command on Windows

The “tar” is originally a *nix command-line utility, but now in the latest versions of Windows, it is officially supported. The use of the “tar” command to zip or unzip files in Windows Command Line is as follows:

Zip Files Using the “tar” Command as follows:

tar -c -f ZipFileName.zip File-To-Zip

Here,

  • The “tar” invokes the “tar” command.
  • The “-c” flag stands for “Create” which means creating the archive.
  • The “-f” flag specifies the name of the output archive.

Below is the execution of the command, but first you must navigate to the specified directory and list files using the following commands:

cd <Path to the Specified Directory>
dir

Now use the following command to create a “.zip” file for the “file.txt”:

tar -c -f files.zip file.txt

Unzip Files Using the “tar” Command

To unzip the files using the “tar” command on Windows, run the following command and replace files.zip with the name or the path to the zipped file you want to extract:

tar -xf files.zip
dir

Zip and Unzip Files Using the “7zip” Utility on Windows

The “7zip” is a popular and open-source cross-platform file management utility that lets you create and extract zip files. To use it on Windows, execute the following command in Windows PowerShell to install Chocolatey – A PowerShell utility to install and manage Windows apps:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

After installing the “Chocolatey” use the below-mentioned command to install “7zip”:

choco install 7zip.install -y

Now to create a zip file of all the text files in the navigated directory using the “7zip”, execute this command:

7z a -t7z files.7z *.txt

Note: You can remove the * from the above command and insert a file name as well.

For unzipping the files using the “7zip”, you need to execute the below command and replace “files.7z” with the file’s name you want to unzip:

7z e files.7z

Note: You can use the “7zip” and “tar” in Windows PowerShell in the same way as the Command Prompt.

Zip and Unzip Files Via the Windows PowerShell

We have already discussed zipping and unzipping the files using the Command Prompt (the same can be used in Windows PowerShell). However, in Windows PowerShell, you can use the “Compress-Archive” cmdlet to zip and “Expand-Archive” to unzip the files.

The “Compress-Archive” is used to create the zip files, as illustrated in the below command:

$compress = @{
>>   Path = "C:\Users\Ali\Documents"
>>   CompressionLevel = "Fastest"                                                    	>>   DestinationPath = "C:\Archives\Draft.zip"                                       	>> }                                                                                 	>> Compress-Archive @compress                                                        	PS C:\WINDOWS\system32> 	

Now check the contents of the directory in which the zipped file is stored:

dir C:\Archives

To unzip the files using the “Expand-Archive” cmdlet, run the following command:

Expand-Archive -Path C:\Archives\Draft.zip -DestinationPath C:\Users\Ali\Documents

That’s all for this post to zip and unzip files in Windows Command Line.

Final Words

To zip and unzip files in Windows Command Line, use the “tar” or “7zip” utilities in either Command Prompt or Windows PowerShell. Additionally, you can use the “Compress-Archive” cmdlet to create a zipped file and “Expand-Archive” to unzip it. This guide has discussed the methods to zip and unzip files using the Windows PowerShell and Command Prompt.

Frequently Asked Questions

How do I zip files using the tar command in Windows Command Line?

To zip files using the tar command in Windows Command Line, use the command 'tar -c -f ZipFileName.zip File-To-Zip' after navigating to the specified directory.

What is the significance of the -c flag when zipping files with the tar command?

The -c flag in the tar command stands for 'Create', indicating that you are creating a new archive when zipping files in Windows Command Line.

How can I unzip files using the 7zip utility in Windows Command Line?

To unzip files using the 7zip utility in Windows Command Line, you can use the 7z command followed by the x option and the name of the file you want to unzip.

What are the advantages of zipping files using the tar command on Windows?

Using the tar command to zip files in Windows allows for efficient compression and archiving, helping save disk space and bandwidth when sharing files.

How does zipping files with the tar command enhance file sharing over the internet?

Zipping files with the tar command reduces file size, making it quicker to upload and download files, thus improving the efficiency of file sharing over the internet.

Can the tar command be used to zip multiple files into a single archive on Windows?

Yes, the tar command can be used to zip multiple files into a single archive on Windows by specifying the files you want to zip in the command.

What are the steps to unzip a .zip file using the Windows Command Prompt?

To unzip a .zip file using the Windows Command Prompt, navigate to the directory where the file is located and use the 'expand' command followed by the name of the .zip file.

How does zipping files using the tar command contribute to saving disk space on Windows?

Zipping files with the tar command compresses them into a smaller size, thus reducing the amount of disk space they occupy, making it an efficient way to save disk space on Windows.