XK0-006 System Management Practice Question
An administrator wants to find all files in /var/log that have been modified within the last 2 days and have a .log extension. Which command should be used?
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 -type f -mtime -2 -name "*.log"
The find command with -mtime -2 finds files modified less than 2 days ago, and -name '*.log' matches the extension.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
find /var/log -mtime 2 -name *.log
Why it's wrong here
find's -mtime 2 matches files modified between 48 and 72 hours ago, not within the last two days, and the unquoted glob is expanded by the shell before find runs. It is tempting because find with -mtime and -name is the right tool, and it would be correct with -mtime -2 and a quoted pattern.
- ✓
find /var/log -type f -mtime -2 -name "*.log"
Why this is correct
The `-mtime -2` test matches files modified less than two days ago, satisfying the recency constraint, while `-name "*.log"` filters by extension and `-type f` excludes directories. Combining these predicates with `find` in `/var/log` returns exactly the required set in one pass.
- ✗
locate --mtime -2 *.log /var/log
Why it's wrong here
locate queries a prebuilt filename database and supports no -mtime option, so it cannot filter by modification time and may return stale paths. It is tempting because locate is fast for finding files by name, and it would be correct when searching the whole filesystem by name pattern alone.
- ✗
ls -la /var/log | grep "\.log$" | head -20
Why it's wrong here
ls lists directory entries and grep filters names; neither inspects modification timestamps, and head truncates output, so the two-day criterion is never evaluated. It is tempting because piping ls into grep is a familiar way to filter filenames, and it would be correct when only matching names matter, not modification age.
About these practice questions
One of 781 original XK0-006 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 XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.