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.atime

(::path | ::IO file_name) -> ::Time
File.atime(object) → time

Returns a new Time object containing the time of the most recent access to the given object. 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.atime(filepath)        # Raises Errno::ENOENT: No such file or directory.
File.write(filepath, 'foo') # Establishes access time.
File.atime(filepath)        # => 2026-10-04 14:23:12.421395099 -0500
File.read(filepath)         # Updates access time.
File.atime(filepath)        # => 2026-10-04 14:23:21.848886816 -0500
File.delete(filepath)       # Clean up.

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

Example
dirpath = '/tmp/foo'
File.exist?(dirpath) # => false
File.atime(dirpath)  # Raises Errno::ENOENT: No such file or directory.
Dir.mkdir(dirpath)   # Establishes access time.
File.atime(dirpath)  # => 2026-10-04 14:35:53.940716253 -0500
Dir.entries(dirpath) # Updates access time.
File.atime(dirpath)  # => 2026-10-04 14:36:24.316018872 -0500
Dir.rmdir(dirpath)   # Clean up.

Argument object may be a string path (as above), a File object, or a Dir object:

Example
File.atime(File.new('/etc/passwd')) # => 2026-10-04 11:25:01.259278928 -0500
File.atime('.')                     # => 2026-10-04 14:40:42.141637825 -0500
See also #atime .absolute_path? .basename .absolute_path also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0