问题原文
原帖链接 · Ress · CC BY-SA 4.0
I'm using grep -ril to be able to see all files that contain a certain string:
[user@machine]$ grep -ril "test string"
file1.log
file2.log
file3.log
file4.log
...
I then would like to zip all of the files that have been returned by that command. Is this possible?
I've tried things such as grep -ril myPattern | zip files.zip and grep -ril myPattern | zip > files.zip but nothing has worked so far.
Is there a workaround to this?
Thank you.
已采纳解答
原帖链接 · Bob · CC BY-SA 4.0
Use the zip command line switch -@ to have zip take the list of input files from standard input instead of from the command line. For example,
grep -ril "test string" | zip name-of-new-zip-file -@
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
