zipnote (创建zip文件后添加注释)

嚯嚯 发表于 2020-07-01 18:31
浏览次数:
在手机上阅读

在类似Unix的操作系统上,zipnote命令可以查看,添加或编辑zipfile的注释。它还允许您重命名存档中包含的文件。 本文档介绍zipnote的Linux版本。

查看英文版

目录

1 zipnote 运行系统环境

2 zipnote 描述

3 zipnote 语法

4 zipnote 示例

zipnote 运行系统环境

Linux

zipnote 描述

zip格式存档的每个文件都可以选择包含注释,这些注释是有关单个文件或整个档案的简短说明或描述。

使用zip实用程序创建zipfile时,可以使用zip的--entry-comments选项添加有关单个文件的注释。您还可以使用zip的--archive-comment选项添加有关整个存档的注释。这些注释将作为归档过程的一部分写入zipfile。

但是,如果要在创建zip文件后添加注释,则可以使用zipnote。

Every file that is archived in the zip format may optionally contain comments, which are short notes or descriptions about individual files or the entire archive.

When you create a zipfile with the zip utility, you can add comments about individual files using zip's --entry-comments option. You can also add a comment about the entire archive using zip's --archive-comment option. These comments will be written to the zipfile as part of the archiving process.

If you want to add comments after a zipfile has already been created, however, you can use zipnote.

查看英文版

查看中文版

zipnote 语法

zipnote [-w] [-b path] [-h] [-v] [-L] zipfile 
-w 从标准输入(stdin)将注释写入zip文件。
-b path 使用路径来存储在注释过程中创建的临时zip文件。
-h 显示帮助消息,然后退出。
-v 显示版本信息,然后退出。
-L 显示软件许可证信息,然后退出。

zipnote如何工作

默认情况下,zipnote会将zipfile的注释转储到标准输出中。

如果要进行更改,可以将该输出重定向到文件,手动进行编辑,然后使用zipnote读取更改并将其写入zipfile。

您还可以使用zipnote在此过程中进行特殊编辑来重命名存档中的文件。

zipfile注释的类型

“归档注释”从整体上描述了归档文件,并且当用户查看归档文件的内容以及用户从归档文件中提取文件时将显示。

“条目注释”描述归档中的各个文件。当用户查看归档文件的内容时显示它们,但是提取文件时通常不显示它们。

可以使用zipnote添加或修改这两种类型的注释。

查看zipfile的注释

假设您有一个名为files.zip的zip文件,其中包含两个文件:file1file2。您可以使用以下命令查看files.zip的注释:

zipnote files.zip

The output will look like this:

@ file1
@ (comment above this line)
@ file2
@ (comment above this line)
@ (zip file comment below this line)

这向我们显示了两个文件file1file2,并且该文件中没有注释。(如果有,我们会在这里看到它们。)

如果我们使用unzip-l选项查看档案中的文件列表,如下所示:

unzip -l files.txt

...our file list will look like this:

Archive:  files.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file1
        0  2014-09-27 15:48   file2
---------                     -------
        0                     2 files

如果有归档文件或单个文件的描述,它们将显示在此处。

添加注释

要使用zipnote更改files.zip中的注释,我们首先需要将zipnote的输出捕获到文件中。让我们将输出重定向到一个名为comments.txt的文件:

zipnote files.zip > comments.txt

现在,在您喜欢的文本编辑器中打开新创建的comment.txt文件,并添加以下行:

@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

保存文件并退出文本编辑器。

接下来,我们将使用-w选项运行zipnote。该命令将如下所示:

zipnote -w files.zip < comments.txt

这个命令的意思是,“使用的内容comments.txt作为输入zipnote,和写(-w)的数据作为新的意见files.zip。” 运行此命令时,我们的编辑将替换files.zip中的注释。

让我们再次使用zipnote来检查我们的更改是否已写入:

zipnote files.zip
@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

我们还可以使用unzip -l列出存档内容,我们将看到我们的新注释:

unzip -l files.zip
Archive:  files.zip
This archive contains two files.
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file1
This is the first file in our archive.
        0  2014-09-27 15:48   file2
This is the second file in our archive.
---------                     -------
        0                     2 files

此外,当我们使用unzip从档案中提取文件时,它会向我们显示档案注释以及其余的输出:

unzip files.zip
Archive:  files.zip
This archive contains two files.
 extracting: file1                   
 extracting: file2

使用zipnote重命名档案中的文件

在对注释的编辑中,可以重命名已归档的文件本身。例如,这是我们正在使用的comment.txt文件:


@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

如果再次在编辑器中将其打开,则可以在文件名下方和注释上方以“ @ = newfilename ” 形式插入一行。例如,让我们将文件file1file2重命名为file-one和file-two。我们通过添加两行来做到这一点,以便comment.txt看起来像这样:

@ file1
@=file-one
This is the first file in our archive.
@ (comment above this line)
@ file2
@=file-two
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

现在,我们像以前一样使用zipnote -w编写更改:

zipnote -w files.zip < comments.txt

...并使用unzip -l检查我们的更改:

unzip -l files.zip
Archive:  files.zip
This archive contains two files.
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file-one
This is the first file in our archive.
        0  2014-09-27 15:48   file-two
This is the second file in our archive.
---------                     -------
        0                     2 files

... 并且voilà,文件已重命名。

zipnote [-w] [-b path] [-h] [-v] [-L] zipfile 
-w Write comments to a zipfile from standard input (stdin).
-b path Use path to store the temporary zip file that is created during the process of annotation.
-h Display a help message, and exit.
-v Display version information, and exit.
-L Display software license information, and exit.

How zipnote works

By default, zipnote will dump a zipfile's comments to standard output.

If you want to make changes, you can redirect this output to a file, edit it manually, and then use zipnote to read in your changes and write them to the zipfile.

You can also use zipnote to rename the files in the archive by making special edits during this process.

Types of zipfile comments

"Archive comments" describe the archive as a whole, and will be displayed when a user views the contents of an archive, and also when a user extracts files from the archive.

"Entry comments" describe individual files in the archive. They are displayed when a user views the contents of an archive, but are usually not shown when the files are extracted.

Both these types of comments can be added or modified using zipnote.

Viewing a zipfile's comments

Let's say you have a zipfile called files.zip, which contains two files: file1 and file2. You can view files.zip's comments using the following command:

zipnote files.zip

The output will look like this:

@ file1
@ (comment above this line)
@ file2
@ (comment above this line)
@ (zip file comment below this line)

This shows us that there are two files, file1 and file2, and that there are no comments in the file. (If there were, we would see them here.)

If we view a list of the files in the archive using the -l option of unzip, like this:

unzip -l files.txt

...our file list will look like this:

Archive:  files.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file1
        0  2014-09-27 15:48   file2
---------                     -------
        0                     2 files

If there were descriptions for the archive or the individual files, they would appear here.

Adding comments

To change the comments in files.zip using zipnote, we first need to capture zipnote's output to a file. Let's redirect the output to a file called comments.txt:

zipnote files.zip > comments.txt

Now, open the newly-created comments.txt file in your favorite text editor, adding lines so that it looks like this:

@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

Save the file and exit your text editor.

Next, we will run zipnote with the -w option. The command will look like this:

zipnote -w files.zip < comments.txt

This command says, "use the contents of comments.txt as input for zipnote, and write (-w) that data as the new comments of files.zip." When this command is run, our edits will replace the comments in files.zip.

Let's use zipnote again, to check that our changes have been written:

zipnote files.zip
@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

We can also use unzip -l to list the archive contents, and we'll see our new comments:

unzip -l files.zip
Archive:  files.zip
This archive contains two files.
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file1
This is the first file in our archive.
        0  2014-09-27 15:48   file2
This is the second file in our archive.
---------                     -------
        0                     2 files

Additionally, when we extract the files from the archive with unzip, it shows us the archive comment with the rest of the output:

unzip files.zip
Archive:  files.zip
This archive contains two files.
 extracting: file1                   
 extracting: file2

Using zipnote to rename the files in your archive

It's possible, in your edits to the comments, to rename the archived files themselves. For instance, here is the comments.txt file we were working with:

@ file1
This is the first file in our archive.
@ (comment above this line)
@ file2
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

If we open this up in our editor again, we can insert a line beneath the file name and above the comment in the form "@=newfilename". For instance, let's rename our files file1 and file2 to file-one and file-two, respectively. We do this by adding two lines so that comments.txt looks like this:

@ file1
@=file-one
This is the first file in our archive.
@ (comment above this line)
@ file2
@=file-two
This is the second file in our archive.
@ (comment above this line)
@ (zip file comment below this line)
This archive contains two files.

Now we write our changes using zipnote -w, as we did before:

zipnote -w files.zip < comments.txt

...and check our changes using unzip -l:

unzip -l files.zip
Archive:  files.zip
This archive contains two files.
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-27 15:48   file-one
This is the first file in our archive.
        0  2014-09-27 15:48   file-two
This is the second file in our archive.
---------                     -------
        0                     2 files

...and voilà , the files have been renamed.

您对zipnote所做的任何更改都没有撤消功能,因此在写入存档之前请仔细检查您的注释文件!您使用-w选项所做的任何更改都是永久性的。

there is no undo function for any of the changes that you make with zipnote, so double check your comments file before writing to the archive! Any changes that you make with the -w option are permanent.

查看英文版

查看中文版

zipnote 示例

zipnote myarchive.zip

以特定于zipnote的格式显示有关myarchive.zip的详细信息,包括所有注释。

zipnote myarchive.zip > mycommentfile.txt

zipnote的输出重定向到文件mycommentfile.txt,将注释信息写入该文件。

zipnote -w myarchive.zip < mycommentfile.txt

mycommentfile.txt的内容重定向到zipnote,后者将其作为输入并将其(-w)作为注释写入myarchive.zip中。

zipnote myarchive.zip

Display details about myarchive.zip, including any comments, in a zipnote-specific format.

zipnote myarchive.zip > mycommentfile.txt

Redirect the output of zipnote to the file mycommentfile.txt, writing the comment information to that file.

zipnote -w myarchive.zip < mycommentfile.txt

Redirect the contents of mycommentfile.txt to zipnote, which takes them as input and writes them (-w) as comments to myarchive.zip.

查看英文版

查看中文版

其他命令行

zipinfo | zipsplit | zip | zipcloak |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条