Skip to content

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

class method

File.lutime

(::Time | ::Numeric atime, ::Time | ::Numeric mtime, *::path file_name) -> ::Integer
File.lutime(atime, mtime, *paths) → path_count

Like File::utime, but does not follow symbolic links, and therefore changes the times of the entries given by paths, regardless of whether they are symbolic links; returns the number of paths given:

Example
# Create a file and a link to it.
file_path = 't.tmp'
File.write(file_path, '')
link_path = 'link'
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 10:45:11.376753268 -0500
file_stat.mtime # => 2026-06-15 10:44:47.335854904 -0500
link_stat.atime # => 2026-06-15 10:44:59.788801128 -0500
link_stat.mtime # => 2026-06-15 10:44:49.367845961 -0500
# Update access time and modification time of the link.
time = Time.now # => 2026-06-15 10:48:57.847422496 -0500
File.lutime(time, time, link_path)
# 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 10:45:11.376753268 -0500
file_stat.mtime # => 2026-06-15 10:44:47.335854904 -0500
# Fetch access time and modification time of link (changed).
link_stat.atime # => 2026-06-15 10:49:27.119146136 -0500
link_stat.mtime # => 2026-06-15 10:48:57.847422496 -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 .mkfifo .link .mtime also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0