Before submitting ZIP files to various third parties, I often have the need to ether remove superfluous files from my archives. Until today I’ve never had the need to add a file to such archives. Had that happened in the past, I would have probably just deleted the whole archive and crated a new one from scratch.
Today I felt adventurous and researched a way to add files to existing ZIP files and found a (not-so-obvious) solution to this puzzle, using the -r switch.
Let me show you how it works:
zip -rv YourArchive.zip NewFile.txt
According to the man page, the r switch actually replaces an existing file in the archive, so this command can be used to update files in the ZIP file too. I’ve added the v switch for convenience (it means “verbose” and can be omitted.
Works on Linux and macOS.