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
file.c
View on GitHub ↗
static VALUE
rb_file_s_chmod(int argc, VALUE *argv, VALUE _)
{
mode_t mode;
apply2args(1);
mode = NUM2MODET(*argv++);
return apply2files(chmod_internal, argc, argv, &mode);
}
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.