>_ IzzyLab

Hands-on task

This task is step 14 of the course “First steps in Linux”

Pack a directory into an archive and unpack it

easy~6 min

The /root/site directory with the website's files needs to go to another server.

  1. Pack it into a compressed archive /root/site.tar.gz. Paths inside the archive must start with site/ — not root/.
  2. Make sure the archive works: create the directory /root/restore and unpack the archive there. You should end up with /root/restore/site — a copy of the original directory.
What you'll practise:
  • tar
  • gzip
  • archives
  • unpacking

Topic breakdown

An archive bundles many files and directories into a single file that's easy to copy and keep. Linux uses tar for this, and gzip compression is added with the z flag — hence the .tar.gz extension.

tar flags are written together, and each has its own job: c — create, x — extract, t — list, z — gzip, f — the archive file name (it comes right after the flags). The dash before the joined flags is optional: tar czf and tar -czf are the same thing; -C does need its dash. An example:

cd /etc
tar czf /tmp/ssh.tar.gz ssh      # pack the ssh directory
tar tzf /tmp/ssh.tar.gz          # paths inside: ssh/...

When unpacking, the archive is extracted into the current directory or into the one given with -C.

What's checked

  1. The archive is gzip-compressed, paths inside start with site/
  2. The archive is unpacked into /root/restore/site
  3. The original directory is in place

What it looks like