Study guide
3.1 Archiving and Compression on the Command Line
LPI Linux Essentials Certificate 010-160
Track your progress as you read
Finished sections get a check mark.
1 Introduction & Exam Overview
1.1 Current Exam Facts 1.2 Study Strategy & Blueprint Weights
2 Topic 1: The Linux Community and a Career in Open Source
1.1 Linux Evolution and Popular Operating Systems 1.2 Major Open Source Applications 1.3 Open Source Software and Licensing 1.4 ICT Skills and Working in Linux
3 Topic 2 Part A: Command Line Basics & Getting Help
2.1a Bash Shell, Command Syntax & Variables 2.1b Quoting, History & Safe Command Syntax 2.2 Using the Command Line to Get Help
4 Topic 2 Part B: Directories, Listing & File Operations
2.3 Using Directories and Listing Files 2.4 Creating, Moving and Deleting Files
5 Topic 3 Part A: Archiving & Searching Data
3.1 Archiving and Compression on the Command Line 3.2a Pipes, Redirection, and Basic Regular Expressions 3.2b grep and Text Extraction Tools
6 Topic 3 Part B: Turning Commands into Scripts
3.3a Script Basics: Shebang, Variables, and Arguments 3.3b Loops, Exit Status, and Simple Conditionals 3.3c Editors, chmod +x, and Running Scripts
7 Topic 4 Part A: Choosing an OS, Hardware & FHS Basics
4.1 Choosing an Operating System 4.2 Understanding Computer Hardware 4.3a Where Programs and Configuration Live (FHS Basics)
8 Topic 4 Part B: Processes, Logs & Networking
4.3b Processes, Memory & Logs 4.4 Your Computer on the Network
9 Topic 5: Security and File Permissions
5.1 Basic Security and Identifying User Types 5.2 Creating Users and Groups 5.3 Managing File Permissions and Ownership 5.4 Special Directories and Files
3.1 Archiving and Compression on the Command Line
Key Takeaways Explain This Topic AI
tar packages many files and directories into one archive; by itself it does not shrink data
Mode flags: -c create, -x extract, -t list; -f must sit immediately before the archive filename
gzip, bzip2, and xz compress single files (.gz, .bz2, .xz); pair them with tar via -z, -j, or -J
.tar.gz/.tgz means a tar archive compressed with gzip; .tar.bz2 uses bzip2 instead
- zip/unzip both archive and compress; use zip -r for directories when exchanging files across platforms
- Last updated: July 2026
Archiving files on the command line (objective 3.1)
Objective 3.1 asks you to turn piles of files into portable packages and to shrink those packages when needed. On Linux Essentials, the core tools are tar , the compressors gzip , bzip2 , and xz , and the cross-platform pair zip / unzip .
Archive versus compress
Keep these jobs separate — exam questions love to mix them up:
- Concept Job Typical tools
- Archive Many files/dirs → one container, keep paths tar , also zip
- Compress Encode data to use fewer bytes gzip , bzip2 , xz
- Both Packed tree and smaller tar -czf … , zip -r …
tar (tape archive) concatenates files and directories into one stream. Alone it does not shrink data. Compression is a second step that modern tar can invoke with helper flags.
tar: create, list, extract
Almost every Essentials-level tar command uses a small flag set:
- Flag Meaning
- c Create a new archive
- x eXtract from an archive
- t lisT contents without extracting
- v Verbose — print names as they are processed
- f Use the archive file named next
Pick exactly one of -c , -x , or -t . -f must immediately precede the archive name — the next argument after -f is the archive path, not another option. tar -cvf project.tar project/ # create
- tar -tf project.tar # list (no write)
- tar -xvf project.tar # extract here
Mnemonic order mode → verbose → file ( -cvf , -tvf , -xvf ) is common. GNU tar also accepts split flags ( tar -c -v -f project.tar … ) as long as -f still sits right before the filename.
Worked create with multiple members: tar -cvf weekend.tar photos/ docs/readme.txt
Tar records paths relative to how you named them. Extracting later rebuilds that tree under your current working directory. Habit: cd to the destination first , then extract; list with -t before -x when the archive came from someone else.
-f trap: tar -cv backup.tar dir/ (without -f before the name) treats backup.tar as a member , not the archive file. Always glue -f to the archive name.
gzip, bzip2, and xz
These tools shrink (or expand) a single file . They do not bundle a directory tree by themselves. gzip report.log # → report.log.gz (original usually removed)
- gunzip report.log.gz # restore (same as gzip -d)
- bzip2 dataset.csv # → dataset.csv.bz2
- bunzip2 dataset.csv.bz2
- xz huge.img # → huge.img.xz
- xz -d huge.img.xz
- Tool Extension Everyday note
- gzip / gunzip .gz Fast, ubiquitous default
- bzip2 / bunzip2 .bz2 Often smaller than gzip; slower
- xz .xz Often smallest; slowest to compress
You do not need algorithm math for 010-160 — know names , extensions , and relative speed versus size .
Pairing compressors with tar
- Filter Compressor Create Extract / list
- z gzip tar -czf a.tar.gz dir/ tar -xzf / tar -tzf
- j bzip2 tar -cjf a.tar.bz2 dir/ tar -xjf / tar -tjf
- J xz tar -cJf a.tar.xz dir/ tar -xJf / tar -tJf tar -czf logs-2026.tar.gz /home/student/app/logs
- tar -tzf logs-2026.tar.gz # verify members first
- tar -xzf logs-2026.tar.gz # extract
Two-step form also exists: tar -cf project.tar project/ then gzip project.tar → project.tar.gz . That is why both .tar.gz and the short .tgz appear in downloads.
.tar.gz versus .tar.bz2
- Extension Meaning
- .tar.gz / .tgz tar archive, then gzip
- .tar.bz2 tar archive, then bzip2
- .tar.xz tar archive, then xz
- .gz / .bz2 / .xz alone compressed single file, not a multi-file tree
If a question emphasizes common / fast backups, prefer gzip ( .tar.gz ). If it emphasizes smallest size and time is available, lean toward xz (or bzip2 as the middle ground). Matching the wrong filter letter — for example -z on a .tar.bz2 — is a frequent exam miss.
Worked restore: List site-backup.tar.bz2 with tar -tjf , then extract with matching -j : cd ~/restore && tar -xjf ~/Downloads/site-backup.tar.bz2 .
zip and unzip
zip both archives and compresses — handy for Windows/macOS handoffs. Use zip -r site.zip site/ and unzip site.zip . Prefer tar + gzip/bzip2/xz for Linux-native backups; use zip when the audience is cross-platform. List zip contents with unzip -l before extracting.
Common exam traps
- Trap Why it fails
- tar -cv backup.tar dir/ (no -f before the name) Name treated as a member, not the archive
- gzip mydir/ expecting one archive of the tree gzip does not package directories
- z extract on .tar.bz2 Wrong filter — use -j
- Swapping -c and -x Create versus extract
- unzip on .tar.gz Wrong family — use tar -xzf
- Exam focus checklist
-f immediately before the archive filename.
Match -c / -x / -t to create / extract / list.
gzip alone does not archive a directory — use tar (or zip -r ).
Match extensions and tar letters: z→gzip , j→bzip2 , J→xz .
Know .tar.gz vs .tar.bz2 and when zip is the cross-platform choice.
Master the archive/compress distinction and those flag patterns, and objective 3.1 becomes reliable points on the 010-160 exam.