Zip

zip 的 -u 標誌是否關注已刪除的文件?

  • August 15, 2013

這個關於 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 中,因為沒有“更新”文件?

在 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

引用自:https://unix.stackexchange.com/questions/86922