【问题标题】:Unix zip command is updating existing archive instead of creating a new oneUnix zip 命令正在更新现有存档而不是创建新存档
【发布时间】:2016-07-29 20:01:24
【问题描述】:
$(which zip) -r ../data.zip .

文件夹的内容随着时间的推移而动态变化,我首先测试它包含huge.pdf文件,后来删除它,但data.zip仍然保持相同的大小。解压后我可以看到huge.pdf 文件。

我正在应用程序 (nodejs) 中执行这个 shell 命令

【问题讨论】:

    标签: linux shell unix zip


    【解决方案1】:

    您可以使用-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.
    

    【讨论】:

    • 请提供文档链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2019-10-05
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多