Difficulty: Medium
Correct Answer: find /usr/ \( -mtime +365 -a -atime +365 \) -ok rm {} \;
Explanation:
Introduction / Context:
Cleaning up stale files on Unix must be done carefully. The find command can select files by access and modification times, while -ok executes a command with an interactive confirmation before each deletion, reducing the risk of accidental data loss.
Given Data / Assumptions:
Concept / Approach:
find supports primary tests for modification time (mtime) and access time (atime), both expressed in days. Parentheses group conditions; -a denotes logical AND. The -ok action runs the specified command prompting '<< ... >> ?' for each candidate. The {} placeholder expands to the found pathname, and commands end with '\;'.
Step-by-Step Solution:
Verification / Alternative check:
First replace -ok with -print to audit matches: find /usr/* \( -mtime +365 -a -atime +365 \) -print. After verifying, switch to -ok rm {} \; for prompted deletions, or use -exec rm {} \; if non-interactive removal is acceptable.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting to escape parentheses in shells; omitting {} and \; in -ok/-exec; using only mtime when access time policy also matters; and running as root without first auditing with -print, which can be hazardous.
Final Answer:
find /usr/ \( -mtime +365 -a -atime +365 \) -ok rm {} \;
Discussion & Comments