Create a symbolic link of existing file / directory in ruby.
linux manual

Basic Usage

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

result = host.ln_s('~/file', '~/file-symlinked')


'symbolic link'


Kanrisuru will throw an error when trying to symlink the root path.


Field Type Description
force boolean
Remove existing destination files


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_s('~/file', '~/file-symlinked').data
  attr_reader :size = 23,
  blocks = 0,
  device = "fc01",
  file_type = "symbolic link",
  gid = 1000,
  group = "ubuntu",
  inode = 260031,
  last_access = #<DateTime: 2021-09-28T07:28:46-05:00 ((2459486j,44926s,657247481n),-18000s,2299161j)>,
  last_changed = #<DateTime: 2021-09-28T07:28:46-05:00 ((2459486j,44926s,657247481n),-18000s,2299161j)>,
  last_modified = #<DateTime: 2021-09-28T07:28:46-05:00 ((2459486j,44926s,657247481n),-18000s,2299161j)>,
  links = 1,
  mode = #<Kanrisuru::Mode:0x900 @numeric=777 @symbolic=lrwxrwxrwx>,
  path = "/home/ubuntu/file-symlinked",
  uid = 1000,
  user = "ubuntu"

Exit Status

Code Description
0 Success
1 Failure

Tested On

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