EX200 tar compression flags Practice Question
An administrator needs to compress a directory containing subdirectories and files into a single archive file, with maximum compression, and exclude all '*.tmp' files. Which command should be used?
⚠ Common exam trap
Red Hat often tests the distinction between compression methods: gzip (-z) is faster but yields larger archives, while bzip2 (-j) provides better compression at the cost of speed. Candidates may assume -z is the default or best option, but for 'maximum compression', bzip2 is superior.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
tar -cjvf archive.tar.bz2 --exclude='*.tmp' /path/to/dir
The question specifies 'maximum compression'. Among common tar compression methods, bzip2 (via the -j flag) typically provides better compression ratios than gzip (-z), though it is slower. Option C uses `tar -cjvf` with the `--exclude` option placed correctly before the source directory, which is the proper syntax for tar exclusions. This command creates a .tar.bz2 archive with maximum compression while excluding all *.tmp files. Option A uses gzip, which offers faster compression but lower ratios, making it incorrect for 'maximum compression'. Options B and D also fail: B has incorrect syntax (--exclude after the directory), and D omits the exclude option entirely.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
tar -czvf archive.tar.gz --exclude='*.tmp' /path/to/dir
Why it's wrong here
This command correctly positions --exclude before the source directory, but relies on -z (gzip), a compression algorithm with a lower compression ratio. The requirement calls for maximum compression, which in GNU tar is achieved with -j (bzip2) or alternatives like xz (-J). Since -z is chosen, the archive is suboptimal; the exclusion filter would work as written, but the compression criterion fails.
- ✗
tar -czvf archive.tar.gz /path/to/dir --exclude='*.tmp'
Why it's wrong here
Here the --exclude option appears after /path/to/dir, a position where GNU tar may not apply it as a pruning rule, meaning *.tmp files could be archived anyway. The command also uses -z (gzip) rather than -j (bzip2), so it fails the maximum-compression requirement. Even if the option order were acceptable, the compression choice alone would make this answer incorrect.
- ✓
tar -cjvf archive.tar.bz2 --exclude='*.tmp' /path/to/dir
Why this is correct
The -j flag invokes bzip2, which provides a considerably higher compression ratio than gzip, satisfying the 'maximum compression' requirement. Placing --exclude='*.tmp' before the source directory ensures the pattern is active before tar reads the files, so temporary files are omitted. The output suffix .tar.bz2 matches the flag and makes the archive self-descriptive.
- ✗
tar -czvf archive.tar.gz /path/to/dir
Why it's wrong here
This command has no --exclude filter at all, so any *.tmp files inside /path/to/dir are swept into the archive, bloating it and defeating the stated need to exclude them. In addition, -z selects gzip, whose compression ratio is lower than bzip2, so it does not meet the maximum-compression requirement. With both the exclusion and compression criteria unmet, this is the least correct option.
Go deeper
Related to this question
About these practice questions
Courseiva writes every EX200 question from scratch — 127 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.