Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.lchmod
(::int mode, *::path file_name) -> ::Integer
File.lchmod(mode, *paths) → paths_count
file.c
View on GitHub ↗
static VALUE
rb_file_s_lchmod(int argc, VALUE *argv, VALUE _)
{
mode_t mode;
apply2args(1);
mode = NUM2MODET(*argv++);
return apply2files(lchmod_internal, argc, argv, &mode);
}
Not supported on Linux or Windows (raises NotImplementedError).
When supported: like File::chmod, but does not follow symbolic links, and therefore changes the mode of the entries given by paths; returns the number of paths given:
Example
File.write('t.tmp', '') File.symlink('t.tmp', 'link') File.lstat('t.tmp').mode.to_s(8) # => "100664" File.lstat('link').mode.to_s(8) # => "120755" File.lchmod(0777, 'link') File.lstat('t.tmp').mode.to_s(8) # => "100664" File.lstat('link').mode.to_s(8) # => "120777" File.delete('t.tmp') File.delete('link')