Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#birthtime
() -> ::Time
birthtime → new_time
file.c
View on GitHub ↗
static VALUE
rb_stat_birthtime(VALUE self)
{
return statx_birthtime(get_stat(self));
}
Returns a new Time object containing the creation time of the snapshot in self. See File System Timestamps:
Example
filepath = '/tmp/t.tmp' File.write(filepath, 'foo') stat = File.stat(filepath) # Take shapshot. stat.birthtime # => 2026-10-05 13:14:24.844158315 -0500 File.delete(filepath) stat.birthtime # => 2026-10-05 13:14:24.844158315 -0500 # Unchanged.
Ruby version changes
-
4.0
-
File::Stat#birthtimeis now available on Linux via the statx system call when supported by the kernel and filesystem. [Feature #21205]
-