Linux · Systems fluency

How do you create, inspect, and extract archives safely?

EasytarcompressionbackupsUpdated Oct 2026
Quiz this track

Short answer

tar bundles files into an archive, and a compressor such as gzip, zstd, or xz reduces size. List an archive before extracting, and never extract an untrusted archive as root without checking its paths.

An archive preserves paths and metadata; compression is a separate step layered on top. tar can call the compressor for you through flags such as -z for gzip, -J for xz, and --zstd for zstd.

sh
tar -czf app.tar.gz ./dist
tar -tzf app.tar.gz | head
tar -xzf app.tar.gz -C /srv/app

Compression choices

  • gzip is ubiquitous and fast enough for most cases
  • zstd offers a better speed-to-ratio trade-off on modern systems
  • xz compresses well but costs more CPU and memory
  • zip is useful for cross-platform exchange but stores metadata differently
  • Compression level tuning matters more for large, repeated archives

Extract into an empty directory and inspect the file list first. Archives can contain absolute paths, parent-directory references, or symlinks that escape the target directory. Modern tar blocks many of these, but the safest workflow is still to verify before extracting.

Backups need more than tar: verify restores, store copies off-host, and protect the archive from tampering. An archive you have never restored is an untested assumption.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between an archive and a compression format?
  2. 2Why should you list a tar archive before extracting it?
  3. 3When would you choose zstd over gzip?
  4. 4What makes a backup different from an archive?

Say it in the interview

tar creates an archive and a compressor reduces its size. I list the archive before extracting and extract into an empty directory, especially for files from outside the team. For backups I verify restores and keep copies off-host, because creating an archive is not the same as having a usable backup.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.