LPIC-1 GNU and Unix Commands Practice Question
A systems administrator needs to find all files in /var/log that were modified in the last 24 hours and contain the word 'error'. Which command accomplishes this?
⚠ Common exam trap
Candidates often confuse `grep` options with `find` options (like `-mtime`) or forget that `grep` alone cannot filter by file modification time, leading them to choose Option A or C without recognizing the missing `-l` flag or syntax errors.
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
✓
find /var/log -mtime 0 -exec grep -l 'error' {} \;
It uses `find` with `-mtime 0` to locate files modified within the last 24 hours, then pipes each found file to `grep -l` to print only filenames containing 'error'. The `-exec` option runs `grep` on each file individually, and `-l` ensures only matching filenames are output, not the matching lines.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
grep -r 'error' /var/log -mtime 0
Why it's wrong here
The -mtime option is not valid for grep.
- ✓
find /var/log -mtime 0 -exec grep -l 'error' {} \;
Why this is correct
Correctly uses find to filter by modification time and grep to search content.
- ✗
find /var/log -mmin 1440 -exec grep 'error' {}
Why it's wrong here
Missing -l flag and broken syntax; also -mmin is not standard for 24 hours.
- ✗
ls -l /var/log | grep error
Why it's wrong here
ls does not search file contents.
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.