Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#utime

(::Integer | ::Time atime, ::Integer | ::Time mtime) -> ::Integer
utime(atime, mtime) → 1

For the entry at the path in self, updates its access time to the given atime and its modification time to the given mtime; each given time may be a Time object, an integer representing a time, or nil (meaning Time.now):

Example
pn = Pathname('/tmp/t.tmp')
pn.write('foo')
pn.atime  # => 2026-09-30 09:00:02.465505713 -0500
pn.mtime  # => 2026-09-30 09:00:02.465505713 -0500
time = Time.now
pn.utime(time, time)
pn.atime  # => 2026-09-30 09:00:23.848023883 -0500
pn.mtime  # => 2026-09-30 09:00:23.848023883 -0500
pn.utime(0, 0)
pn.atime  # => 1969-12-31 18:00:00 -0600
pn.mtime  # => 1969-12-31 18:00:00 -0600
pn.utime(nil, nil)
pn.atime  # => 2026-09-30 09:01:02.492202169 -0500
pn.mtime  # => 2026-09-30 09:01:02.492202169 -0500
pn.delete # Clean up.

Follows symbolic links; use Pathname#lutime to update the times for a symbolic link.