For the Unix/Linux touch command, which specific option targets changing only the access time (atime) of a file?

Difficulty: Easy

Correct Answer: -a

Explanation:


Introduction / Context:
While touch can modify both access and modification timestamps, administrators and build systems often need to control them independently. Selecting the correct switch avoids unintended changes and preserves audit trails where mtime should remain untouched.


Given Data / Assumptions:

  • You intend to adjust only atime.
  • mtime should remain unchanged unless explicitly set.
  • Standard GNU/BSD touch semantics apply.


Concept / Approach:
The -a option tells touch to change the access time only. The -m option (not listed in distractors) changes the modification time only. The -t option supplies an explicit timestamp but, by itself, affects both atime and mtime unless combined with -a or -m. Options -b and -h are unrelated here (-h affects symlink timestamps on some systems).


Step-by-Step Solution:

Inspect current times: stat notes.txtUpdate only atime to now: touch -a notes.txtSet only atime to a specific time: touch -a -t 202507201200 notes.txtRe-check with stat to confirm mtime is unchanged.


Verification / Alternative check:
Compare stat output before and after running 'touch -a'. You should see atime updated while mtime stays the same, proving that -a is the correct, targeted switch.


Why Other Options Are Wrong:

  • -t: Provides a timestamp but affects both times unless paired with -a/-m.
  • -b: Not a standard touch option for times.
  • -h: On some systems operates on the symlink itself; not a time selector.
  • None of the above: Incorrect because -a is the correct choice.


Common Pitfalls:
Forgetting that -t requires format YYYYMMDDhhmm[.ss], and overlooking mount options like relatime which may delay atime updates on access.


Final Answer:
-a

Discussion & Comments

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