Basically I am working on a shell script in Cygwin which requires me to zip a couple of files (it must be a zip can't be gzip). The server I'm working on does not have the zip binary installed and I can not install it as it would require an RFC (request for change) to be done.

The only way I can create a zip for now is to select the files I want in Windows environment right click > send to compressed zip folder. But this defeats the purpose of having a shell script to do the work.

Is there ANY other way I can do this either through the Unix shell or Windows CMD?

  • Moreover to Celada's answer, you should also be able to install zip locally.
    – pfnuesel
    Apr 15, 2017 at 20:46

2 Answers 2


Sure, use the Python zipfile module. Python is quite ubiquitously installed, so you probably won't need to request to have it installed. The zipfile module comes with Python's standard library, so it's essentially guaranteed to be installed if Python itself is.

You can use it either by writing a short Python script, or by using its own command line interface (examples at the end of the documentation page).


Sure, just use powershell. Example below creates foo.zip, containing foo.txt.

PS C:\Users\steve_000> Compress-Archive -U -LiteralPath foo.txt -DestinationPath foo.zip
PS C:\Users\steve_000> dir foo.zip

    Directory: C:\Users\steve_000

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         15/04/17  10:52 PM           1119 foo.zip

PS C:\Users\steve_000>

More details at https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.archive/Compress-Archive

  • 2
    Can this be done in a shell script running in Cygwin though? I know absolutely nothing about powershell but isn't it a Windows thing? Is there some sort of trick to bridge the *nix shell running in Cygwin and powershell?
    – terdon
    Apr 15, 2017 at 22:42
  • note - this is only available starting with PowerShell 5 (February 2016)
    – Zombo
    Apr 16, 2017 at 1:12
  • Just run powershel.exe 'commands in quotes' from your script. stackoverflow.com/questions/14044671/…
    – steve
    Apr 16, 2017 at 6:31
  • If you don't have PowerShell 5 you can use the native .NET compression routines directly by calling them in a PowerShell script.
    – dragon788
    Apr 16, 2017 at 13:07

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .