Wednesday, June 16, 2010

Gzip and Tar

Gzip:

  1. Gzip is used to compress a file. To zip "thisfile", type gzip thisfile. You'll get a file named thisfile.gz.
  2. $gzip thisfile
  3. $thisfile.gz
  4. To unzip thisfile.gz, type gunzip thisfile.gz.
  5. $gunzip thisfile.gz
  6. Gzip supports 9 levels of compression; 1 being the fastest and least compressed; 9 being the slowest and most compressed; 6 being the default. To get the best compression, use the command: gzip -9 readme

Tar:

  1. Tar is used to pack the entire contents of a directory or directories into a single file called a tarball.
  2. Tar preserves the entire directory organization including file ownership, permissions, links, and the directory structure.
  3. The most commonly used tar functions are:

  • c - create an archive
  • x - extract files from an archive
  • t - list the contents of an archive
  • v - verbose
  • f filename - use the specified file
  • z - gzip/gunzip

Examples: Back |up the contents of the home directory for gemini (/home/gemini) in a tarball called a.tar on a floppy disk.


  1. mount /floppy
    cd /home
    tar -cvf /floppy/a.tar gemini


    Explanation:
    • Change to the parent of the /home/gemini directory.
    • Create a backup of gemini in the file /floppy/a.tar.
  2. Now, check the contents of the tarball that you just created.

    cd /floppy
    tar -tvf a.tar

  3. Back |up the contents of the etc directory in an archive called etc.tar . Make sure that the archive is created in your own home directory.

    cd /
    tar -cvf ~/etc.tar etc


    Explanation:
    • Change to the parent of the /etc directory.
    • Create a backup of etc in the file ~/etc.tar
  4. Back |up and compress the contents of the home directory into the tarball home.tgz on a floppy disk.

    mount /floppy
    cd /
    tar -cvzf /floppy/home.tgz home


    Explanation:
    • change to the parent of the /home directory
    • Create a compressed backup of home in the file /floppy/home.tgz.
  5. Now check the contents of the archive that you just created.

    cd /floppy
    tar -tvzf home.tgz

  6. Unpack the archive home.tgz on your floppy.

    cd /floppy
    tar -xvzf home.tgz


    Explanation:
    • change to the /floppy directory
    • unpack and unzip the tarball home.tgz

No comments:

Post a Comment