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

wc

Get number of lines, words and characters of a file in ruby.
linux manual

Basic Usage

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

result = host.wc('/etc/hosts')
result.success?
true

result.lines
20

result.words
45

result.characters
443

Parameters

Field Type Description
paths string
Required file to get counts for.

Result

Returns a single FileCount struct.

FileCount Fields

Field Type Description
lines integer The number of newline counts in a file.
words integer The number of word counts in a file.
characters integer The number of characters in a file.

Return Example

host.wc("/etc/hosts").data
#<Struct:Kanrisuru::Core::File::FileCount:0x000005a0
  characters = 443,
  lines = 20,
  words = 45
>

Exit Status

Code Description
0 Success
1 Failure

Tested On

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