In its most basic usage zip is invoked like this zip options zipfile file For

In its most basic usage zip is invoked like this zip

This preview shows page 264 - 266 out of 540 pages.

In its most basic usage, zip is invoked like this: zip options zipfile file... For example, to make a zip archive of our playground, we would do this: [[email protected] ~]$ zip -r playground.zip playground Unless we include the -r option for recursion, only the playground directory (but none of its contents) is stored. Although the addition of the extension .zip is automatic, we will include the file extension for clarity. During the creation of the zip archive, zip will normally display a series of messages like this: adding: playground/dir-020/file-Z (stored 0%) adding: playground/dir-020/file-Y (stored 0%) adding: playground/dir-020/file-X (stored 0%) adding: playground/dir-087/ (stored 0%) adding: playground/dir-087/file-S (stored 0%) These messages show the status of each file added to the archive. zip will add files to the archive using one of two storage methods: Either it will “store” a file without com- pression, as shown here, or it will “deflate” the file which performs compression. The nu- meric value displayed after the storage method indicates the amount of compression achieved. Since our playground only contains empty files, no compression is performed on its contents. Extracting the contents of a zip file is straightforward when using the unzip program: 240
Image of page 264
Archiving Files [[email protected] ~]$ cd foo [[email protected] foo]$ unzip ../playground.zip One thing to note about zip (as opposed to tar ) is that if an existing archive is speci- fied, it is updated rather than replaced. This means that the existing archive is preserved, but new files are added and matching files are replaced. Files may be listed and extracted selectively from a zip archive by specifying them to unzip : [[email protected] ~]$ unzip -l playground.zip playground/dir-087/file-Z Archive: ../playground.zip Length Date Time Name -------- ---- ---- ---- 0 10-05-16 09:25 playground/dir-087/file-Z -------- ------- 0 1 file [[email protected] ~]$ cd foo [[email protected] foo]$ unzip ../playground.zip playground/dir-087/file-Z Archive: ../playground.zip replace playground/dir-087/file-Z? [y]es, [n]o, [A]ll, [N]one, [r]ename: y extracting: playground/dir-087/file-Z Using the -l option causes unzip to merely list the contents of the archive without ex- tracting the file. If no file(s) are specified, unzip will list all files in the archive. The -v option can be added to increase the verbosity of the listing. Note that when the archive extraction conflicts with an existing file, the user is prompted before the file is replaced. Like tar , zip can make use of standard input and output, though its implementation is somewhat less useful. It is possible to pipe a list of filenames to zip via the [email protected] option: [[email protected] foo]$ cd [[email protected] ~]$ find playground -name "file-A" | zip [email protected] file-A.zip Here we use find to generate a list of files matching the test -name "file-A" , and then pipe the list into zip , which creates the archive file-A.zip containing the se- lected files.
Image of page 265
Image of page 266

You've reached the end of your free preview.

Want to read all 540 pages?

  • Fall '14
  • .........

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture