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#lutime

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

Like Pathname#utime, but does not follow symbolic links, and therefore changes the times of the entry in self, regardless of whether it is a symbolic link:

Example
# Create a file and a link to it.
file_path = 't.tmp'
link_path = 'link'
File.write(file_path, '')
File.symlink(file_path, link_path)
# Take snapshots of both.
file_stat = File.stat(file_path)
link_stat = File.lstat(link_path)
# Fetch access times and modification times of both.
file_stat.atime # => 2026-06-15 11:03:29.600373255 -0500
file_stat.mtime # => 2026-06-15 11:03:22.247352211 -0500
link_stat.atime # => 2026-06-15 11:03:29.251372254 -0500
link_stat.mtime # => 2026-06-15 11:03:26.66436484 -0500
# Update access time and modification time of the link.
pn = Pathname(link_path)
time = Time.now # => 2026-06-15 11:08:07.384287523 -0500
pn.lutime(time, time)
# Take fresh snapshots of both.
file_stat = File.stat(file_path)
link_stat = File.lstat(link_path)
# Fetch access time and modification time of file (not changed).
file_stat.atime # => 2026-06-15 11:03:29.600373255 -0500
file_stat.mtime # => 2026-06-15 11:03:22.247352211 -0500
# Fetch access time and modification time of link (changed).
link_stat.atime # => 2026-06-15 11:08:29.847301399 -0500
link_stat.mtime # => 2026-06-15 11:08:07.384287523 -0500
# Clean up.
File.delete(file_path)
File.delete(link_path)

Arguments atime and mtime may be Time objects (as above).

Either or both may be integers; when an integer i is passed, Time.new(i) is used.

Either or both may be nil, in which case Time.now is used.

See File System Timestamps.

See also #lstat #make_link #lchown #make_symlink also in 4.0 · 3.4 · 3.3 · 3.2