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
file.c
View on GitHub ↗
static VALUE
rb_file_s_lutime(int argc, VALUE *argv, VALUE _)
{
return utime_internal_i(argc, argv, TRUE);
}
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.