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

(::path file_name) -> ::File::Stat
File.stat(path) → stat

Returns a new File::Stat object for the entry at path. Unlike File.lstat, does follow symbolic links; therefore if the entry is a symbolic link, the returned object contains information for the target entry, not the symbolic link:

Example
filepath = '/etc/passwd'
linkpath = '/tmp/foo'
File.symlink(filepath, linkpath)
# Method File.stat follows the symlink, so the birthtimes are the same.
File.stat(filepath).birthtime  # => 2025-06-10 11:10:47.358999941 -0500
File.stat(linkpath).birthtime  # => 2025-06-10 11:10:47.358999941 -0500
# Method File.lstat does not follow the symlink, so the birthtimes are different.
File.lstat(filepath).birthtime # => 2025-06-10 11:10:47.358999941 -0500
File.lstat(linkpath).birthtime # => 2026-09-23 14:01:18.248754979 -0500
File.delete(linkpath)          # Clean up.
See also .split .sticky? .socket? .symlink also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0