Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

FileUtils#rm_r

rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)

remove files list[0] list[1]… If list[n] is a directory, removes its all contents recursively. This method ignores StandardError when :force option is set.

Example
FileUtils.rm_r Dir.glob('/tmp/*')
FileUtils.rm_r 'some_dir', force: true

WARNING: This method causes local vulnerability if one of parent directories or removing directory tree are world writable (including /tmp, whose permission is 1777), and the current process has strong privilege such as Unix super user (root), and the system has symbolic link. For secure removing, read the documentation of remove_entry_secure carefully, and set :secure option to true. Default is secure: false.

NOTE: This method calls remove_entry_secure if :secure option is set. See also remove_entry_secure.

See also .rm_r #rm_f #rm_rf #rmdir also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0