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#lstat

() -> (::File::Stat | nil)
lstat → stat

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

Example
file_path = '/etc/passwd'
link_path = '/tmp/foo'
File.symlink(file_path, link_path)
file = File.new(file_path) # => #<File:/etc/passwd>
link = File.new(link_path) # => #<File:/tmp/foo>
# Method lstat does not follow the symlink, so the birthtimes are different.
file.lstat.birthtime       # => 2025-06-10 11:10:47.358999941 -0500
link.lstat.birthtime       # => 2026-09-23 16:35:59.321566598 -0500
# Method stat does follow the symlink, so the birthtimes are the same.
file.stat.birthtime        # => 2025-06-10 11:10:47.358999941 -0500
link.stat.birthtime        # => 2025-06-10 11:10:47.358999941 -0500
File.delete(link_path)     # Clean up.
See also .lstat #flock #mtime #ctime also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0