Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
File::Stat
A File::Stat object contains information about an entry in the filesystem.
Each of these methods returns a new File::Stat object. the first three follow symbolic links; the others don’t:
Snapshot
A new File::Stat object takes an immediate “snapshot” of the filesystem entry at the given ‘path’; the snapshot is never updated, regardless of changes in the entry (even its deletion):
filepath = '/tmp/t.tmp' File.stat(filepath) # Raises Errno::ENOENT: No such file or directory. File.write(filepath, 'foo') stat = File.stat(filepath) stat.birthtime # => 2026-10-03 12:19:23.723062465 -0500 File.delete(filepath) stat.birthtime # => 2026-10-03 12:19:23.723062465 -0500
Filesystem Dependencies
Methods in a File::Stat object may return filesystem-dependent values, and not all values are meaningful on all filesystems; for example, File::Stat#blocks returns nil on a Windows filesystem, but returns an integer on others.
See also Kernel#test.
Class methods 1
Instance methods 43
Ruby version changes 1
-
4.0
-
File::Stat#birthtimeis now available on Linux via the statx system call when supported by the kernel and filesystem. [Feature #21205]
-