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

(::int mode, *::path file_name) -> ::Integer
File.lchmod(mode, *paths) → paths_count

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')
See also .join .lchown .identical? .link also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0