zip files from stdin

Zip command in bash can read file list from stdin or from pipe.
e.g.

1
tar *.txt|zip file.zip -

will zip the tar ball piped to stdin (noted with a “-”). However,

1
ls *.txt|zip file.zip -

will NOT zip all txt files into the zip package, because a “-” means just ONE file from stdin.
Instead, we should use

1
ls *.txt|zip file.zip -@

. “-@” means read all files piped to stdin.
Although this is clearly mentioned in the man page, I cannot easily file an answer of a question like
“How to pipe multiple files to zip command?” by googling the internet.

Share this:
Facebook Linkedin Twitter Digg Email

Leave a Reply