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
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1997
def utime(atime, mtime) File.utime(atime, mtime, @path) end
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.
See also
#unlink
#world_readable?
#truncate
#world_writable?
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0