Skip to content

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

instance method

File::Stat#atime

() -> ::Time
atime → time

Returns a new Time object containing the access time of the snapshot in 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.write(filepath, 'foo')
File.atime(filepath)        # => 2026-10-04 14:58:58.805179514 -0500
stat0 = File.stat(filepath) # Take snapshot.
stat0.atime                 # => 2026-10-04 14:58:58.805179514 -0500
File.read(filepath)         # Updates file atime.
File.atime(filepath)        # => 2026-10-04 14:59:47.707059351 -0500
stat0.atime                 # => 2026-10-04 14:58:58.805179514 -0500 # Not updated.
stat1 = File.stat(filepath) # Take new snapshot.
stat1.atime                 # => 2026-10-04 14:59:47.707059351 -0500 # Updated.
File.delete(filepath)       # Clean up.

Access time for a directory is established when it is created, and may be updated when its entries are read:

“‘ruby dirpath = ’/tmp/dir’ Dir.mkdir(dirpath) File.atime(dirpath) # => 2026-10-04 15:07:26.194548647 -0500 stat0 = File.stat(dirpath) # Take snapshot. stat0.atime # => 2026-10-04 15:07:26.194548647 -0500 Dir.entries(dirpath) # Updates directory atime. File.atime(dirpath) # => 2026-10-04 15:08:14.818746815 -0500 # Updated. stat0.atime # => 2026-10-04 15:07:26.194548647 -0500 # Not updated. stat1 = File.stat(dirpath) # Take new shapshot. stat1.atime # => 2026-10-04 15:08:14.818746815 -0500 # Updated. Dir.rmdir(dirpath) # Clean up.

See also #<=> #birthtime .new #blksize also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0