I’m trying to create a zip file from file contents which are being piped in, e.g.
mysql [params and query] | zip -q output.zip -
This writes the zip correctly, but when you open the zip, the file within it is called “-“. Is there any way of specifying what the filename of the piped in data should be within the zip?
From what i can gather you cannot do both with the
zipcommand, i mean you cannot both specify the filenames and pipe the content. You can either pipe the contents and the resulting file is-or you can pipe the filenames with-@.That does not mean that doing so is impossible using other techniques. I outline one of those below. It does mean that you have to have PHP installed and the zip extension loaded.
There could be a whole bunch of other ways to do it. But this is the easiest that I know of. Oh and it’s a one-liner too.
This is a working example using PHP
To run on windows just swap single and double quotes. Or just place the script in a file.
“test.zip” is the resulting Zip file, “testfile” is the name of the contents that are being piped into the command.
Result from
unzip -l test.zipAnd here is a working example using python
Result of
unzip -lResult of
unzip -p