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

(::int mode) -> (0 | nil)
chmod(mode) → 0

Changes the mode of self; returns ‘0’. See Filesystem Modes and especially Setting a Mode.

Example
filepath = '/tmp/t.tmp'
File.write(filepath, 'foo')
'%06o' % File.stat(filepath).mode      # => "100664"
file = File.new(filepath)
file.chmod(0o755)
'%06o' % File.stat(filepath).mode      # => "100755"
# Clean up.
file.close
File.delete(filepath)
See also .chmod #birthtime #chown #atime also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0