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

$(which zip) -r ../data.zip . 

The contents of the folders are changing dynamically overtime, I tested it first with including huge.pdf file and later deleted it, but still data.zip stays the same size. On unzipping I could see the huge.pdf file there.

I wish that zip command overrides the existing archive completely.

and I'm executing this shell command in an application (nodejs)

Edit: I don't think so the linked question is duplicate.


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.

As it states the zip command's help entry:

The default action is to add or replace zipfile entries from list

This explains why the default behavior does not involve deleting files in the zipfile, and the reason why huge.pdf remains in it.

If you want to override the existing archive completely, you could create a new temporary zipfile and then replace the previous one. Also, the which command invocation does not appear to be necessary, so the command should be the following:

zip -r temp.zip . ; mv temp.zip ../data.zip

Category: shell Time: 2016-07-29 Views: 0
Tags: shell zip

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.154 (s). 12 q(s)