LFCS Essential Commands Practice Question
A junior administrator needs to create a compressed archive of the /etc directory that preserves file ownership and permissions, and writes it to /backup/etc.tar.gz. Which single command accomplishes this?
⚠ Common exam trap
Candidates often confuse the create flag -c with the extract flag -x when the stem asks to build an archive.
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 -czvf /backup/etc.tar.gz /etc
Creating a gzip-compressed tarball requires the create, gzip, verbose, and file flags together with the source directory. The combination tar -czvf /backup/etc.tar.gz /etc builds the archive in one pass, preserving metadata, and writes it to the specified path. The other commands either attempt extraction, misuse compression tools, or produce non-tar output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
gzip -r /etc > /backup/etc.tar.gz
Why it's wrong here
This fails because gzip compresses individual files and cannot bundle a directory tree into a single archive. Redirecting gzip output writes raw compressed bytes to stdout, not a valid tar archive. The resulting file would not be a usable archive and the redirection would capture only the compressed stream, not a directory structure.
- ✓
tar -czvf /backup/etc.tar.gz /etc
Why this is correct
This is correct because tar with the -c flag creates a new archive, -z compresses it with gzip, -v shows progress, and -f specifies the archive filename. By default tar preserves ownership and permission metadata when creating archives as root, exactly matching the requirement to archive /etc into /backup/etc.tar.gz.
- ✗
cpio -ov /etc < /backup/etc.tar.gz
Why it's wrong here
This command is incorrect because cpio reads the list of files from stdin, not from a redirection of the output archive, and the input redirection here points to the destination file rather than a file list. Additionally, cpio does not produce gzip-compressed tar archives by itself, so the output format would not match the required .tar.gz.
- ✗
tar -xzvf /backup/etc.tar.gz /etc
Why it's wrong here
This is wrong because the -x flag extracts an archive rather than creating one. Running this against a nonexistent /backup/etc.tar.gz would fail or, if the file existed, it would unpack its contents into the current directory. The scenario requires archive creation, so the create flag -c is needed instead of -x.
Go deeper
Related to this question
About these practice questions
One of 406 original LFCS practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 Linux Foundation exam blueprint
This LFCS practice question is part of Courseiva's free Linux Foundation 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 LFCS exam.