Zip

如何創建在提取時列印消息的 ZIP 文件?

  • November 22, 2020

最近,我遇到了一個 zip 文件(包含單個文件),它在我執行時將自定義消息列印到標準輸出

unzip archive.zip

沒有進一步的論據。

我不知道這是可能的。我確實閱讀了 ZIP 規範中的文件註釋,但它們在 CLI 上的行為似乎有所不同。

當我使用zip -c並輸入自定義消息時,我可以看到我的自定義消息以某種方式被壓縮到存檔中,但是當再次解壓縮文件時它不會自動列印。

使用unzip -l可以讓我查看我的消息——但這不是原始文件的archive.zip行為方式。unzip -l archive.zip首先列印自定義消息,然後列出存檔內容。與我對文件評論的實驗相反,評論沒有列印在列表中。

因此我的問題是:如何創建一個在提取時列印自定義消息的 ZIP 文件?(而且,如果不是文件評論,這個功能叫什麼?)

我想你正在尋找--archive-comment. 從手冊頁引用:

      -z
      --archive-comment
             Prompt  for a multi-line comment for the entire zip archive.  The comment is ended by a line containing just a period, or an end of file condition (^D on Unix, ^Z on MSDOS, OS/2, and
             VMS).  The comment can be taken from a file:

                    zip -z foo < foowhat

zip --archive-comment -c -r test test提示使用者為整個存檔輸入特殊註釋。

在提取期間(消息是 Hello):

unzip ../test.zip
Archive:  ../test.zip
Hello.
  creating: test/
extracting: test/test.txt

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