$(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/