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

stat

Get file information in ruby.
linux manual

Basic Usage

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

result = host.stat('/etc/resolv.conf')
result.success?
true

result.path
'/etc/resolv.conf'

result.inode
665

result.group
'root'

result.user
'root'

Parameters

Field Type Description
path string
Required path to get the file information for.
follow boolean
Whether to follow symbolic links or not.

Result

Returns a single FileStat struct.

FileStat Fields

Field Type Description
mode Kanrisuru::Mode The mode bits set for the file / directory.
blocks integer The number of blocks allocated for the file.
device string The major and minor device number combined into one value (in hex and decimal) of the device on which the file resides.
file_type string What's the file type, ie: directory, file, block_device, char_device, symlink
gid integer The group id in which the file belongs to.
group string The group name in which the file belongs to.
links integer Number of hard links pointing to the underlying inode.
inode integer Unique inode value assigned to the file
path string Where is the file located at
fsize integer Size of the file (in bytes)
uid integer The user id that owns the file
user string The user that owns the file
last_access DateTime When was the last time the file was accessed.
last_modified DateTime When was the last time the file was updated.
last_change DateTime When was the last time the file was changed.

Return Example

result = host.stat('/etc/resolv.conf', follow: true)
result.data
#<Struct:Kanrisuru::Core::Stat::FileStat:0x00000668
  attr_reader :size = 739,
  blocks = 8,
  device = "1a",
  file_type = "regular file",
  gid = 103,
  group = "systemd-resolve",
  inode = 672,
  last_access = #<DateTime: 2021-12-28T05:01:45-06:00 ((2459577j,39705s,642151867n),-21600s,2299161j)>,
  last_changed = #<DateTime: 2021-12-26T01:30:53-06:00 ((2459575j,27053s,461292704n),-21600s,2299161j)>,
  last_modified = #<DateTime: 2021-12-26T01:30:53-06:00 ((2459575j,27053s,461292704n),-21600s,2299161j)>,
  links = 1,
  mode = #<Kanrisuru::Mode:0x960 @numeric=644 @symbolic=-rw-r--r-->,
  path = "/etc/resolv.conf",
  uid = 101,
  user = "systemd-resolve"
>

Exit Status

Code Description
0 Success
1 Failure

Tested On

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