How do you specify filenames within a zip when creating it on the command line from a pipe?

user245425 picture user245425 · Jan 7, 2010 · Viewed 18.2k times · Source

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?

Answer

Didier Trosset picture Didier Trosset · Jan 7, 2010

You can use a named pipe, and send the request output to it, while zipping from it.

mkfifo output.txt ; mysql [params and query] > output.txt & zip output.zip -FI output.txt ; rm output.txt