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

copy(src, dest, preserve: nil, noop: nil, verbose: nil)

Alias of #cp

Copies a file content src to dest. If dest is a directory, copies src to dest/src.

If src is a list of files, then dest must be a directory.

Example
FileUtils.cp 'eval.c', 'eval.c.org'
FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true
FileUtils.cp 'symlink', 'dest'   # copy content, "dest" is not a symlink
See also #cp .copy #compare_stream #copy_entry also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0