1

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?

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

2 Answers 2

7

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).

0

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

5
  • 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? Commented Apr 15, 2017 at 22:42
  • note - this is only available starting with PowerShell 5 (February 2016) Commented Apr 16, 2017 at 1:12
  • Just run powershel.exe 'commands in quotes' from your script. stackoverflow.com/questions/14044671/… Commented 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. Commented Apr 16, 2017 at 13:07
  • On Windows there's always PowerShell 5, unless you're using an EOL OS. PowerShell is available for *nix so this command can be used on Linux as well Commented Apr 16 at 8:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.