Unix zip命令正在更新现有存档而不是创建新存档

时间:2016-07-29 20:01:24

标签: linux shell unix zip

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

文件夹的内容正在随时间动态变化,我首先测试它包含huge.pdf文件,然后将其删除,但仍然data.zip保持相同的大小。在解压缩时,我可以在那里看到huge.pdf文件。

我在应用程序(nodejs)中执行此shell命令

1 个答案:

答案 0 :(得分:1)

您可以对filesync使用-FS参数:

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

当前目录中不存在且已经存在于zip中的所有文件都将从中删除,并且所有新文件都将添加到该文件中。

来自man zip

-FS
       --filesync
              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.