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

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

Changes the modes of each of the entries at each the given paths; returns the count of the given paths. See Filesystem Modes and especially Setting a Mode.

Example
file0path = '/tmp/t0.tmp'
file1path = '/tmp/t1.tmp'
File.write(file0path, 'foo')
File.write(file1path, 'bar')
'%06o' % File.stat(file0path).mode # => "100664"
'%06o' % File.stat(file1path).mode # => "100664"
File.chmod(0o755, file0path, file1path)
'%06o' % File.stat(file0path).mode # => "100755"
'%06o' % File.stat(file1path).mode # => "100755"
File.delete(file0path, file1path)  # Clean up.
See also #chmod .chardev? .chown .blockdev? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0