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.

Kanrisuru

head

Output the first part of a file in ruby.
linux manual

Basic Usage

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

result = host.head('/etc/crontab', lines: 5)
result.success?
true

result.to_a
[
  [0] "# /etc/crontab: system-wide crontab",
  [1] "# Unlike any other crontab you don't have to run the `crontab'",
  [2] "# command to install the new version when you edit this file",
  [3] "# and files in /etc/cron.d. These files also have username fields,",
  [4] "# that none of the other crontabs do."
]

Parameters

Field Type Description
path string
Required file path to get the contents from.
bytes integer
Print the first K bytes of each file; with the leading '-', print all but the last K bytes of each file
lines integer
Print the first K lines instead of the first 10; with the leading '-', print all but the last K lines of each file
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

Result

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

Exit Status

Code Description
0 Success
1 Failure

Tested On

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