mkdir
Create a directory 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.mkdir('test')
result.success?
true
host.path
'/home/ubuntu/test'
Parameters
Field | Type | Description |
---|---|---|
path |
string
|
Required name of the directory that is being created |
owner |
string
integer
|
Owner of the directory |
group |
string
integer
|
Group the directory should belong to |
recursive |
boolean
|
Recursively update all sub-directories and files to the specified owner / group. |
silent |
boolean
|
No error if directory already exists, make parent directories as needed |
mode |
Kanrisuru::Mode
string
|
The mode bits set for the directory. |
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.mkdir("new-directory", owner: 0, group: 0, recursive: true).data
#<Struct:Kanrisuru::Core::Stat::FileStat:0x000006b8
fsize = 4096,
blocks = 8,
device = "fc01",
file_type = "directory",
gid = 0,
group = "root",
inode = 371928,
last_access = #<DateTime: 2021-08-25T12:17:55-05:00 ((2459452j,62275s,570593100n),-18000s,2299161j)>,
last_changed = #<DateTime: 2021-08-25T12:17:55-05:00 ((2459452j,62275s,570593100n),-18000s,2299161j)>,
last_modified = #<DateTime: 2021-08-25T12:17:23-05:00 ((2459452j,62243s,142213183n),-18000s,2299161j)>,
links = 2,
mode = #<Kanrisuru::Mode:0x1000 @numeric=775 @symbolic=drwxrwxr-x>,
path = "/home/ubuntu/directory",
uid = 0,
user = "root"
>
Additional Examples
result = host.mkdir("~/make/nested/directories/", silent: true)
result.success?
true
result.path
"/home/ubuntu/make/nested/directories/"
Exit Status
Code | Description |
---|---|
0 | Success |
1 | Failure |
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES