Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File#atime
() -> ::Time
atime → time
file.c
View on GitHub ↗
static VALUE
rb_file_atime(VALUE obj)
{
rb_io_t *fptr;
struct stat st;
GetOpenFile(obj, fptr);
if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail_path(fptr->pathv);
}
return stat_time(stat_atimespec(&st));
}
Returns a new Time object containing the time of the most recent access to self. See File System Timestamps.
Access time for a file is established when it is created, and may be updated when the file content is read:
Example
filepath = '/tmp/t.tmp' File.exist?(filepath) # => false File.write(filepath, 'foo') # Establishes access time. file = File.new(filepath) file.atime # => 2026-10-04 14:48:30.323100327 -0500 file.read # Updates access time. file.atime # => 2026-10-04 14:49:01.104340829 -0500 # Clean up. file.close File.delete(filepath)