Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.lstat
(::path file_name) -> ::File::Stat
File.lstat(path) → stat
file.c
View on GitHub ↗
static VALUE
rb_file_s_lstat(VALUE klass, VALUE fname)
{
#ifdef HAVE_LSTAT
rb_io_stat_data st;
FilePathValue(fname);
fname = rb_str_encode_ospath(fname);
if (lstatx_without_gvl(StringValueCStr(fname), &st, STATX_ALL) == -1) {
rb_sys_fail_path(fname);
}
return rb_statx_new(&st);
#else
return rb_file_s_stat(klass, fname);
#endif
}
Returns a new File::Stat object for the entry at path. Unline File.stat, does not follow symbolic links; therefore the returned object contains information for the entry at path, regardless of whether is a symbolic link:
Example
filepath = '/etc/passwd' linkpath = '/tmp/foo' File.symlink(filepath, linkpath) # 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 # 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 File.delete(linkpath) # Clean up.