FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next 

Archiving and compressing



  1. Large files can be gzipped the files to save space.
  2. The command to gzip the file readme is: gzip readme
    This will compress the readme file and save the result in a file called readme.gz.
  3. The command to gunzip the file readme.gz is: gunzip readme.gz
  4. 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 is used to pack the entire contents of a directory or directories into a single file called a tarball which can then be backed up to tape, gzipped and saved, or transferred to another system. Tar preserves the entire directory organization including file ownership, permissions, links, and the directory structure. Tar stands for tape archive because it was developed to backup files on tape. Now, most of the Linux software available on the Internet is stored as gzipped tar files.

The most commonly used tar functions are:

Additionally, there are commonly used options:


  1. Back |up the contents of the home directory for alterego (/home/alterego) in a tarball called a.tar on a floppy disk.
    mount /floppy
    cd /home
    tar -cvf /floppy/a.tar alterego

  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

  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

  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



  1. Practice gunzip.
  2. Unpack a tarball.
  3. More gzipping/gunzipping:
  4. Create and unpack a tar archive of the directory /home.
  5. More practice:

Questions & Answers:

  1. Which command will give best compression?
    a.  gzip -1 lab10.html
    b.  gzip -9 lab10.html
    Answer:  b
  2. Which command will display the contents of a gzipped file on the screen but leave the actual file unchanged?
    a.  gzip -c lab10.gzip
    b.  gzip -d lab10.gzip
    Answer:  a
  3. Which command will create archive the labs directory in a tarball called labs.tar?
    a.  tar -cvf labs labs.tar
    b.  tar -cvf labs.tar labs
    Answer:  b
  4. Which command will unpack the tarball labs.tar?
    a.  tar -xf labs.tar
    b.  tar -tf labs.tar
    Answer:  a

Copyright © L.M.MacEwan
FLOPPIX Home | FAQ | Download | Labs | ToC | Back |  Next