【发布时间】:2016-07-29 20:01:24
【问题描述】:
$(which zip) -r ../data.zip .
文件夹的内容随着时间的推移而动态变化,我首先测试它包含huge.pdf文件,后来删除它,但data.zip仍然保持相同的大小。解压后我可以看到huge.pdf 文件。
我正在应用程序 (nodejs) 中执行这个 shell 命令
【问题讨论】:
$(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.
【讨论】: