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

标签 linux shell unix zip

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

文件夹的内容随着时间的推移动态变化,我首先使用包含 huge.pdf 文件进行测试,然后将其删除,但 data.zip 仍然保持不变尺寸。解压缩时,我可以看到那里的 huge.pdf 文件。

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

最佳答案

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

关于linux - Unix zip 命令正在更新现有存档而不是创建新存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38666626/

相关文章:

c++ - 在 Linux for x86 上检测异常浮点运算

linux - 在 Fortran 代码中执行 execute_command_line() 时出错

unix - `rm` 一个名为 '--help' 的文件?

linux - 在 unix 中列出文件并将输出保存在变量中(获取特定扩展名的最旧文件)

java - 是否有一个java库相当于unix中的文件命令

linux - 需要修复 if else 脚本

C++ 如何在两个不同项目中的静态变量之间发生链接

linux - 打印文件名列表(文本文件中指定的文件名除外)

java - 同时从多个线程调用 shell 脚本

linux - 在多个 shell 上运行 bash 脚本