Linux zipnote command

Updated: 04/26/2017 by Computer Hope

About 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. zipnote is a tool you can use to view, add, or edit a zipfile's comments. It also allows you to rename files contained in the archive.

Overview

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 syntax

zipnote [-w] [-b path] [-h] [-v] [-L] zipfile

Options

-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 within 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 will show 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 just 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, just 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.

Warning: 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 examples

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.

unzip — List, test and extract compressed files in a zip archive.
zip — A compression and archiving utility.
zipcloak — Encrypt files within an existing zip archive.
zipsplit — Split a single zip archive into a set of smaller zip files.