Finding stale files by access time: With the Unix find command, which primary selects files that have not been accessed for more than 365 days?

Difficulty: Easy

Correct Answer: -atime +365

Explanation:


Introduction / Context:
System cleanup often targets files that have not been used recently. The find command offers predicates for selecting files by last access time (atime) and last modification time (mtime). Choosing the correct predicate avoids deleting files that are still in use.



Given Data / Assumptions:

  • The selection criterion is based on last access, not last modification.
  • “More than 365 days” means strictly older than 365 days.
  • We are using standard POSIX find semantics where +N means greater than N days.


Concept / Approach:

-atime n selects files accessed exactly n24 hours ago; -atime +n selects files accessed more than n24 hours ago; -atime -n selects files accessed less than n*24 hours ago. The corresponding predicates for modification are -mtime.



Step-by-Step Solution:

We need last access time older than 365 days.Use -atime because the criterion is access-based.Use the greater-than form: -atime +365.Example command: find /path -type f -atime +365 -print


Verification / Alternative check:

To check matches without deleting, first run with -print. To combine with deletion and confirmation, use -ok rm {} \; or to delete directly, -exec rm {} \;. You can also pair with -mtime if you additionally require no recent modifications.



Why Other Options Are Wrong:

  • -mtime + 365: Uses modification time, not access time; also the space is harmless but not standard style.
  • -atime -365: Selects files accessed within the last 365 days (less than), not older.
  • -mtime -365: Uses modification time and less than; wrong dimension and comparison.
  • None of the above: Incorrect because -atime +365 is correct.


Common Pitfalls:

Confusing atime with mtime; forgetting that find counts in 24-hour units, not calendar days; not quoting parentheses when combining predicates; and testing delete actions on the wrong directory tree.



Final Answer:

-atime +365

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion