This is the development version of Kanrisuru. Since this is still a pre-1.0 release, we don't recommend using this in system-critical production environments.



Copy files and directories in ruby
linux manual

Basic Usage

require 'kanrisuru'
host = '', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])'~/test.txt')

result = host.cp('~/test.txt', '~/test-copy.txt')


Field Type Description
source string
Required A list of files / directories to copy
destination string
Required If the the source was a single file, destination can either be a file or directory to copy the file to. For multiple files, the destination is a directory to copy to
backup boolean
Makes a backup of each existing destination file
recursive boolean
This option will copy directories recursively
one_file_system boolean
Stay on this file system
update boolean
Copy only when the source file is newer than the destination file or when the destination file is missing
follow boolean
Follow command line links in source
no_clobber boolean
Do not overwrite an existing file
strip_trailing_slashes boolean
Remove any trailing slashes from each source argument.
preserve boolean
Preserves the file / directory attributes of source to destination (default - mode,ownership,timestamps)
no_target_directory boolean
Treat destination as a normal file
target_directory string
Copy all source arguments into directory


No explicit data struct returned, only option is success?, failure?, and status to see if the program exited properly.

Return Example

result = host.cp(['file1.conf', 'file2.conf', 'file3.conf'], 'dir')

host.cp(['file1.conf', 'file2.conf', 'file3.conf'], 'dir', backup: true).status
0 '~/dir').map(&:path)

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES