LPIC-1 GNU and Unix Commands Practice Question
You are a Linux administrator for a company that runs a web server on a system with limited disk space. The web server logs are stored in /var/log/httpd/access_log and grow quickly. The operations team requires that the most recent logs be available for troubleshooting, but logs older than 7 days must be compressed to save space. You decide to implement log rotation using logrotate. The logrotate configuration file for httpd currently contains:
/var/log/httpd/*.log { daily rotate 7 compress delaycompress missingok notifempty sharedscripts postrotate /bin/systemctl reload httpd 2>/dev/null || true endscript
}
After applying this configuration, you notice that log files are being compressed immediately instead of after one rotation. What is the most likely cause and the correct step to fix this?
⚠ Common exam trap
The trap here is that candidates may misinterpret 'delaycompress' as causing immediate compression, when in fact it delays compression by one rotation, and the issue is actually the rotation frequency being too short relative to the retention period.
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
✓
Change the rotation frequency to 'weekly' so that the most recent week's logs remain uncompressed and older logs are compressed.
The issue is that with daily rotation, the delaycompress directive delays compression by only one rotation (one day). This means that rotated logs are compressed after one day, not after the desired 7 days. To meet the requirement that logs older than 7 days are compressed, the rotation frequency should be changed to weekly. With weekly rotation, delaycompress delays compression by one week, so logs younger than 7 days remain uncompressed and the most recent week's logs are available for troubleshooting.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Remove the 'sharedscripts' directive to ensure the postrotate script runs for each log file individually.
Why it's wrong here
The sharedscripts directive does not affect compression timing; it only controls when the postrotate script runs.
- ✓
Change the rotation frequency to 'weekly' so that the most recent week's logs remain uncompressed and older logs are compressed.
Why this is correct
With weekly rotation, the most recent rotated log (one week old) remains uncompressed due to delaycompress, while older logs are compressed, meeting the requirement of compressing logs older than 7 days.
- ✗
Remove the 'delaycompress' directive to ensure compression occurs at each rotation.
Why it's wrong here
Removing delaycompress would cause all rotated logs to be compressed immediately, including the most recent, which contradicts the requirement to keep recent logs uncompressed.
- ✗
Add the 'copytruncate' directive to avoid moving the log file, allowing the web server to continue writing to the same file.
Why it's wrong here
copytruncate does not affect compression timing; it only changes how the log file is rotated.
Go deeper
Related to this question
About these practice questions
One of 527 original LPIC-1 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 by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
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.