Output contents of a file in ruby.
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.cat('/etc/hosts')

  [ 0] " localhost",
  [ 1] " ubuntu",
  [ 2] "",
  [ 3] .. [16],
  [17] "ff02::1 ip6-allnodes",
  [18] "ff02::2 ip6-allrouters",
  [19] "ff02::3 ip6-allhosts"


Field Type Description
path string
Required file path to get the contents from.
show_tabs boolean
Display tab characters
number boolean
number all output lines
squeeze_blank boolean
suppress repeated empty output lines
show_nonprinting boolean
use ^ and M- notation, except for LFD and TAB
show_ends boolean
display $ at end of each line
number_nonblank boolean
number nonempty output lines
show_all boolean
Show all fields including nonprinting, ends, and tabs
mode string
Can be either append or write options. Determines how content is saved into a file.
new_file string
The name of the newfile to write the content to


Either returns an array of all lines from the file, or a nil value if a file is being written to.

Additional Examples

host.cat(['~/ssl.csr', '~/ssl.ca.bundle'], 
  mode: 'write', 
  new_file: '/var/www/site/ssl/ssl.csr'

Exit Status

Code Description
0 Success
1 Failure

Tested On

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