Unix zip command is updating existing archive instead of creating a new one

First note that executing zip through $(which zip) is the same as executing it as just zip. The which utility locates a program file in the user's path.

Given an existing Zip archive, zip will add new files, replace existing files, but it will not delete files in the archive if those files have been removed from the file system.

To delete a file from a Zip archive:

$ zip -d archive.zip filename

You may obviously also just remove the archive with rm before re-creating it.

For your NodeJS script, you could use

rm -f ../data.zip && zip -r ../data.zip .

The -f flag to rm makes rm not fail if the archive does not exist.

Tags:

Shell

Zip