Lesson 3.8: Compressing and archiving files
The difference between an archive and compression: tar to pack (c), list (t) and extract (x) many files as one, gzip/gunzip/zcat to compress, and the .tar.gz files you'll meet everywhere.
15 min
You will learn to
- Explain archiving vs compressing
- Create, list and extract archives with tar -c, -t, -x
- Combine them with -z for .tar.gz
- Compress and read single files with gzip and zcat
Key terms
- Archive
- One file that contains many files and directories together with their names, paths and permissions.
- Compression
- Re-encoding data so it takes fewer bytes, without losing anything (lossless).
- tar
- The standard archiving tool: c create, t list, x extract, f archive file, v verbose, z gzip, -C change directory first.
- .tar.gz (.tgz)
- An archive that was then compressed with gzip; the most common way to distribute and back up files on Linux.
- gzip / gunzip / zcat
- Compress a single file to FILE.gz, decompress it back, or print the decompressed content without changing the file.
- Tarbomb
- An archive that extracts hundreds of files straight into the current directory, or uses paths like ../ to write elsewhere. Listing first (tar -t) prevents surprises.
← Hard and symbolic links · All lessons · Searching the filesystem: find and locate →