zip 的 -u 标志是否关注已删除的文件?

zip 的 -u 标志是否关注已删除的文件?

这个网站关于 Linux 的 zip 实用程序是这样描述该-u标志的:

仅当 zip 存档中的现有条目的修改时间比 zip 存档中已有的版本更新时,才替换(更新)该条目。例如:

        zip -u stuff * 

will add any new files in the current directory, and update any files which 

自上次创建/修改 zip 存档 stuff.zip 以来已被修改。

我的问题是,如果某个特定文件自上次压缩以来已被删除,是否-u会识别出该文件已被删除,从而将其从 *.zip 文件中删除?或者,缺少时间戳信息(因为文件现已删除),它会将备份文件保留在 *.zip 中,因为没有“较新”文件?

答案1

在 zip 版本 3.0 上有:

   The new File Sync option (-FS) is also considered a new mode, though it
   is similar to update.  This mode  synchronizes  the  archive  with  the
   files  on  the OS, only replacing files in the archive if the file time
   or size of the OS file is different, adding  new  files,  and  deleting
   entries from the archive where there is no matching file.  As this mode
   can delete entries from the archive, consider making a backup  copy  of
   the archive.

我想这就是你所追求的?

如果你想要将文件保留在存档中,然后-u执行以下操作:

$ mkdir test && touch test/{flibble,foobaz,blurp}
$ zip -r test test
  adding: test/ (stored 0%)
  adding: test/foobaz (stored 0%)
  adding: test/flibble (stored 0%)
  adding: test/blurp (stored 0%)
$ rm test/flibble && touch test/{,flibble}
$ zip -ru test test
updating: test/ (stored 0%)
updating: test/flibble (stored 0%)
$ unzip -l test
Archive:  test.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2013-08-15 22:04   test/
        0  2013-08-15 22:04   test/foobaz
        0  2013-08-15 22:04   test/flibble
        0  2013-08-15 22:04   test/blurp
---------                     -------
        0                     4 files

相关内容