user2727195 user2727195 - 1 year ago 53
Bash Question

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

$(which zip) -r ../ .

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

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

Answer Source

You can use -FS argument to filesync :

$(which zip) -FSr ../ .

All files not present in current directory and already present in the zip will be deleted from it and all new files will be added to it.

From man zip :

              Synchronize the contents of an archive with the files on the OS.  Normally when an archive is updated, new files are added and changed files are updated but files that no longer  exist
              on  the  OS  are  not deleted from the archive.  This option enables a new mode that checks entries in the archive against the file system.  If the file time and file size of the entry
              matches that of the OS file, the entry is copied from the old archive instead of being read from the file system and compressed.  If the OS file has changed, the entry is read and com‐
              pressed  as  usual.   If the entry in the archive does not match a file on the OS, the entry is deleted.  Enabling this option should create archives that are the same as new archives,
              but since existing entries are copied instead of compressed, updating an existing archive with -FS can be much faster than creating a new archive.  Also consider using -u for  updating
              an archive.