LFCS Essential Commands Practice Question
A developer accidentally deleted a critical file /var/log/app.log. The system administrator knows that the file was recently backed up using a cron job that runs 'tar -czf /backup/logs.tar.gz /var/log/'. Which command should the administrator use to restore the file from the backup without extracting the entire archive?
⚠ Common exam trap
Watch out — candidates often assume `tar -xf` works with `.tar.gz` files without the `-z` flag, or that `cp` can directly reference files inside a tar archive using a colon syntax, which is not supported by the standard `cp` command.
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 -xzf /backup/logs.tar.gz --to-stdout var/log/app.log > /var/log/app.log
`tar -xzf` extracts the specified file (`var/log/app.log`) from the compressed archive and `--to-stdout` sends its content to standard output, which is then redirected to recreate the file at `/var/log/app.log`. This restores the single file without extracting the entire archive, matching the requirement precisely.
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 -xf /backup/logs.tar.gz var/log/app.log
Why it's wrong here
Extracts only the specified file, but fails to decompress the gzip archive because the -z flag is omitted, so it will likely produce an error or extract corrupted data.
- ✗
tar -tf /backup/logs.tar.gz | grep app.log
Why it's wrong here
Lists the contents of the archive and filters for app.log, but does not extract any file.
- ✓
tar -xzf /backup/logs.tar.gz --to-stdout var/log/app.log > /var/log/app.log
Why this is correct
Ly uses tar -xzf with --to-stdout to decompress and extract only the specified file, then redirects the content to restore the file without extracting the entire archive.
- ✗
cp /backup/logs.tar.gz:/var/log/app.log /var/log/app.log
Why it's wrong here
Uses an invalid syntax for cp; it cannot directly reference files inside a tar archive.
Go deeper
Related to this question
About these practice questions
This LFCS question is part of Courseiva's 507-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 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.