- A
:> /var/log/nginx/access.log && cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && gzip /var/log/nginx/access.log.bak
Why wrong: Truncating first loses current log content before copy.
- B
cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && :> /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak
Correct: copies the file, truncates the original (keeping inode), compresses the copy.
- C
rm /var/log/nginx/access.log && touch /var/log/nginx/access.log && chmod 644 /var/log/nginx/access.log
Why wrong: Deleting and recreating changes inode; nginx may stop writing.
- D
mv /var/log/nginx/access.log /var/log/nginx/access.log.bak && touch /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak
Why wrong: Moving changes inode; nginx will not write to new file until restarted.
Quick Answer
The correct answer is to use `cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && :> /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak`. This sequence works because the `:>` (or `>`) redirection truncates the log file in place without changing its inode, meaning Nginx’s open file descriptor remains valid and the service continues writing to the same file uninterrupted. The backup copy is then compressed to reclaim disk space, directly addressing the need to truncate the log file without stopping Nginx. On the LFCS exam, this scenario tests your understanding of Linux file descriptors, inodes, and safe log management under the Filesystem and Storage objectives. A common trap is assuming you must restart or send a SIGHUP signal to Nginx after truncation, but that is only required if you delete and recreate the file. The key memory tip is: “Truncate in place, compress the copy—no service stop, no file descriptor drop.”
LFCS Essential Commands Practice Question
This LFCS practice question tests your understanding of essential commands. This is a configuration task: choose the command set that satisfies every stated requirement. Small differences — like 'secret' vs 'password' or 'transport input ssh' vs 'all' — change whether the answer is correct. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
You are a system administrator for a company that runs a web server on a Linux system. The web server logs are stored in /var/log/nginx/access.log. The log file grows rapidly and rotates weekly via logrotate. The system has been running for several months. Recently, the development team reported that the web server is responding slowly. You suspect that the disk I/O might be high due to log file activity. You check the disk usage and find that /var/log/nginx/access.log is 4 GB, and the rotated logs (access.log.1.gz, access.log.2.gz, etc.) total another 10 GB. The /var partition has 20 GB total, so it's 70% full. You decide to reduce the disk usage by compressing the current log file and truncating it without stopping the nginx service. Which command sequence should you use to safely achieve this?
Clue words in this question
Noticing these words before you look at the options changes how you read each choice.
Clue:
"which command"Why it matters: Tests specific CLI syntax. Recall the exact command and its required context — near-synonyms and partial matches are common distractors.
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
cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && :> /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak
Option B is correct because it first copies the current log file to a backup, then truncates the original file in place using the shell null command (`:>`) without stopping nginx, and finally compresses the backup. This ensures nginx continues writing to the same inode (file descriptor remains valid) and the disk space is reclaimed after compression.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
:> /var/log/nginx/access.log && cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && gzip /var/log/nginx/access.log.bak
Why it's wrong here
Truncating first loses current log content before copy.
- ✓
cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && :> /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak
Why this is correct
Correct: copies the file, truncates the original (keeping inode), compresses the copy.
Clue confirmation
The clue word "which command" in the question point toward this answer.
Related concept
Read the scenario before looking for a memorised answer.
- ✗
rm /var/log/nginx/access.log && touch /var/log/nginx/access.log && chmod 644 /var/log/nginx/access.log
Why it's wrong here
Deleting and recreating changes inode; nginx may stop writing.
- ✗
mv /var/log/nginx/access.log /var/log/nginx/access.log.bak && touch /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak
Why it's wrong here
Moving changes inode; nginx will not write to new file until restarted.
Common exam traps
Common exam trap: answer the scenario, not the keyword
The trap here is that candidates often choose `mv` and `touch` (Option D) thinking it's the standard logrotate method, but without signaling nginx, the old file descriptor remains attached to the moved file, causing the new empty file to be ignored and log data to be written to the renamed file instead.
Detailed technical explanation
How to think about this question
Under the hood, nginx holds an open file descriptor to the inode of `/var/log/nginx/access.log`. Truncating with `:>` (or `>`) writes to the same inode, so nginx's file offset remains valid and logging continues seamlessly. Copying before truncation preserves the data, and compressing the copy reclaims disk space. In real-world scenarios, logrotate uses a similar approach (copytruncate) to avoid service interruption, but manual intervention may be needed when logs grow unexpectedly.
KKey Concepts to Remember
- Read the scenario before looking for a memorised answer.
- Find the constraint that changes the correct option.
- Eliminate answers that are true in general but not in this case.
TExam Day Tips
- Watch for words such as best, first, most likely and least administrative effort.
- Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the LFCS exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
- →
Essential Commands — study guide chapter
Learn the concepts, then practise the questions
- →
Essential Commands practice questions
Targeted practice on this topic area only
- →
All LFCS questions
513 questions across all exam domains
- →
Linux Foundation Certified System Administrator LFCS study guide
Full concept coverage aligned to exam objectives
- →
LFCS practice test guide
How to use practice tests most effectively before exam day
Related practice questions
Related LFCS practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
User and Group Management practice questions
Practise LFCS questions linked to User and Group Management.
Operation of Running Systems practice questions
Practise LFCS questions linked to Operation of Running Systems.
Essential Commands practice questions
Practise LFCS questions linked to Essential Commands.
Networking practice questions
Practise LFCS questions linked to Networking.
Service Configuration practice questions
Practise LFCS questions linked to Service Configuration.
Storage Management practice questions
Practise LFCS questions linked to Storage Management.
LFCS fundamentals practice questions
Practise LFCS questions linked to LFCS fundamentals.
LFCS scenario practice questions
Practise LFCS questions linked to LFCS scenario.
LFCS troubleshooting practice questions
Practise LFCS questions linked to LFCS troubleshooting.
Practice this exam
Start a free LFCS practice session
Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.
FAQ
Questions learners often ask
What does this LFCS question test?
Essential Commands — This question tests Essential Commands — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: cp /var/log/nginx/access.log /var/log/nginx/access.log.bak && :> /var/log/nginx/access.log && gzip /var/log/nginx/access.log.bak — Option B is correct because it first copies the current log file to a backup, then truncates the original file in place using the shell null command (`:>`) without stopping nginx, and finally compresses the backup. This ensures nginx continues writing to the same inode (file descriptor remains valid) and the disk space is reclaimed after compression.
What should I do if I get this LFCS question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Are there clue words in this question I should notice?
Yes — watch for: "which command". Tests specific CLI syntax. Recall the exact command and its required context — near-synonyms and partial matches are common distractors.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 11, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.