LPIC-1 GNU and Unix Commands Practice Question
A junior administrator needs to extract only the file 'etc/nginx/nginx.conf' from the archive 'backup.tar.bz2' into the current directory, preserving its path structure. Which command should be used?
⚠ Common exam trap
Candidates often confuse the -c (create) and -x (extract) flags, or forgetting that -j is required for bzip2 and -z for gzip.
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 -xjvf backup.tar.bz2 etc/nginx/nginx.conf
To extract a single file from a bzip2-compressed tarball while keeping its stored path, use tar with -x, -j, -v, and -f, followed by the exact member name. Omitting -j would fail on bzip2 compression, and using -c would create rather than extract. The member name must match the archived path exactly to select only that file.
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 -xjf backup.tar.bz2 --strip-components=1 etc/nginx/nginx.conf
Why it's wrong here
The --strip-components=1 option removes the first directory component from extracted paths. If the archive member is 'etc/nginx/nginx.conf', stripping one component would yield 'nginx/nginx.conf', losing the 'etc' directory. The requirement is to preserve the path structure, so this option is incorrect.
- ✗
tar -xjvf backup.tar.bz2 | grep nginx.conf
Why it's wrong here
Piping tar output to grep only filters the verbose listing; it does not extract the file. The -x flag is present but the pipe redirects stdout, so the file is still extracted to disk, but the grep is unnecessary and misleading. However, the command as written does extract all files, not just the specified one, because the member argument is missing.
- ✗
tar -cjvf backup.tar.bz2 etc/nginx/nginx.conf
Why it's wrong here
The -c option creates a new archive instead of extracting from an existing one. Using -c with an existing archive name would overwrite or append depending on other flags, but here it would attempt to create a new archive from the specified file. This does not extract anything and risks data loss if the archive is overwritten.
- ✓
tar -xjvf backup.tar.bz2 etc/nginx/nginx.conf
Why this is correct
This command uses tar with -x to extract, -j to filter through bzip2, -v for verbose output, and -f to specify the archive file. The path 'etc/nginx/nginx.conf' selects only that member. Because the stored path is relative, the file is extracted into ./etc/nginx/nginx.conf, preserving the directory structure.
Go deeper
Related to this question
About these practice questions
Courseiva writes every LPIC-1 question from scratch — 402 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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official LPI exam blueprint
This LPIC-1 practice question is part of Courseiva's free LPI 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 LPIC-1 exam.