>_ IzzyLab

Hands-on task

This task is step 5 of the course “Shipping a release”

Archive a directory, excluding a subdirectory

medium~5 min

Build a gzip archive /root/site.tar.gz from the directory /root/site, but exclude the cache subdirectory cache (its contents must not end up in the archive). Include everything else — index.html and css/.

What you'll practise:
  • tar
  • gzip
  • file exclusion
  • --exclude
  • archives

Topic breakdown

When building an archive, tar recursively walks the directory and packs everything indiscriminately, but some paths can be filtered out by pattern, so that cache, temporary, or junk directories don't bloat the archive. This is handled by the exclusion option, which takes a glob pattern; it can be specified multiple times, and the pattern is matched against the path inside the archive. The rest is standard: the create mode, the gzip compression flag, and the output file name.

What's checked

  1. required files in the archive
  2. cache excluded

What it looks like