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

touch

Change file timestamps 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.touch('new-file.txt')
result.success?
true

result[0].path
'/home/ubuntu/new-file.txt'

result[0].last_access.to_s
'2021-10-06T17:03:56-05:00'

result[0].last_changed.to_s
'2021-10-06T17:03:56-05:00'

result[0].last_modified.to_s
'2021-10-06T17:03:56-05:00'

Parameters

Field Type Description
paths string
array
Required paths of files to update the timestamp
atime boolean
Change only the access time
mtime boolean
Change only the modification time
date string
Date
Use date as the time to update the file timestamps.
nofiles boolean
Do not create any files
reference string
Use a separate file as the timestamp to update the paths provided

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.touch(['new-file.txt', 'another-file.txt'], reference: '/etc/hosts').data
[
  #<Struct:Kanrisuru::Core::Stat::FileStat:0x00000618
    attr_reader :size = 0,
    blocks = 0,
    device = "fc01",
    file_type = "regular empty file",
    gid = 1000,
    group = "ubuntu",
    inode = 363260,
    last_access = #<DateTime: 2021-10-05T21:27:22-05:00 ((2459494j,8842s,455133150n),-18000s,2299161j)>,
    last_changed = #<DateTime: 2021-10-06T17:13:21-05:00 ((2459494j,80001s,143934740n),-18000s,2299161j)>,
    last_modified = #<DateTime: 2021-07-26T17:52:28-05:00 ((2459422j,82348s,499589336n),-18000s,2299161j)>,
    links = 1,
    mode = #<Kanrisuru::Mode:0x920 @numeric=664 @symbolic=-rw-rw-r-->,
    path = "new-file.txt",
    uid = 1000,
    user = "ubuntu"
  >,
  #<Struct:Kanrisuru::Core::Stat::FileStat:0x000007a8
    attr_reader :size = 0,
    blocks = 0,
    device = "fc01",
    file_type = "regular empty file",
    gid = 1000,
    group = "ubuntu",
    inode = 365045,
    last_access = #<DateTime: 2021-10-05T21:27:22-05:00 ((2459494j,8842s,455133150n),-18000s,2299161j)>,
    last_changed = #<DateTime: 2021-10-06T17:13:21-05:00 ((2459494j,80001s,143934740n),-18000s,2299161j)>,
    last_modified = #<DateTime: 2021-07-26T17:52:28-05:00 ((2459422j,82348s,499589336n),-18000s,2299161j)>,
    links = 1,
    mode = #<Kanrisuru::Mode:0x1120 @numeric=664 @symbolic=-rw-rw-r-->,
    path = "another-file.txt",
    uid = 1000,
    user = "ubuntu"
  >

Exit Status

Code Description
0 Success
1 Failure

Tested On

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