learn how to zip filesog post, we will learn how to zip files and folders using the
Windows 10 command line, a skill that can come in handy when you want to
automate compression tasks or perform them remotely.
Using PowerShell
Since Windows 7, PowerShell has been included with the Windows operating
system. We can use PowerShell to compress files and folders without the
need for any third-party tools. Follow these steps to zip files using
PowerShell:
-
Press
WIN+X
on your keyboard and select
Windows PowerShell or
Windows PowerShell (Admin) from the menu. -
Navigate to the directory containing the files you wish to compress
using the cd command. For example, if your files are
located inC:UsersYourUsernameDocumentsMyFiles
, you
would type:
cd C:UsersYourUsernameDocumentsMyFiles
-
Use the following command to compress your files and folders into a
zip archive:
Compress-Archive -LiteralPath Source_Folder -DestinationPath Destination_Archive.zip
Replace Source_Folder
with the name of the folder you want to
compress and Destination_Archive.zip
with the desired name
of your zip file. For example:
Compress-Archive -LiteralPath MyFiles -DestinationPath MyFiles.zip
If you want to compress individual files, you can separate them with
commas:
Compress-Archive -LiteralPath file1.txt, file2.txt, file3.txt -DestinationPath Files.zip
Using Command Prompt
If you prefer using the Command Prompt, you can use the built-in
tar and curl commands available in
Windows 10 to compress files and folders. Here’s how:
-
Press
WIN+R
on your keyboard, type cmd,
and pressEnter
to open the Command Prompt. -
Navigate to the directory containing the files you wish to compress
using the cd command, just like in PowerShell. -
Use the following command to compress your files and folders into a
zip archive:
tar -a -c -f Destination_Archive.zip Source_Folder
Replace Source_Folder
with the name of the folder you want to
compress and Destination_Archive.zip
with the desired name
of your zip file. For example:
tar -a -c -f MyFiles.zip MyFiles
To compress individual files, you can list them after the
-f
option:
tar -a -c -f Files.zip file1.txt file2.txt file3.txt
Conclusion
Now you know how to zip files and folders using the command line on
Windows 10, both with PowerShell and the Command Prompt. This can be
especially helpful when automating tasks or working on remote systems.