Kanrisuru

ln

Create a hard link (copy) of existing file with shared inode 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.ln('~/file', '~/file-linked')
result.success?
true

result.inode
260444

host.stat('~/file').inode
260444

Hard linking a directory is not an available option with Kanrisuru.

Parameters

Field Type Description
force boolean
Remove existing destination files

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

host.ln('~/file1', '~/file-linked').data
#<Struct:Kanrisuru::Core::Stat::FileStat:0x00000708
  attr_reader :size = 0,
  blocks = 0,
  device = "fc01",
  file_type = "regular empty file",
  gid = 1000,
  group = "ubuntu",
  inode = 260444,
  last_access = #<DateTime: 2021-09-26T22:50:32-05:00 ((2459485j,13832s,878017037n),-18000s,2299161j)>,
  last_changed = #<DateTime: 2021-09-27T08:28:12-05:00 ((2459485j,48492s,779006117n),-18000s,2299161j)>,
  last_modified = #<DateTime: 2021-09-26T22:47:46-05:00 ((2459485j,13666s,243887733n),-18000s,2299161j)>,
  links = 2,
  mode = #<Kanrisuru::Mode:0x880 @numeric=664 @symbolic=-rw-rw-r-->,
  path = "file-linked",
  uid = 1000,
  user = "ubuntu"
>

Exit Status

Code Description
0 Success
1 Failure

Tested On

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