du
Get an estimate of disk usage space in ruby
linux manual
Basic Usage
require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
host.su('root')
result = host.du(path: '/etc', summarize: true)
result.success?
true
result[0].path
'/etc'
result[0].fsize
5704
This command needs escalated privlidges to access certain directories.
Parameters
Field | Type | Description |
---|---|---|
path |
string
|
A path to get disk usage total |
summarize |
boolean
|
If true, this will summarize the total disk usage of the path, otherwise, it will get disk usage for each nested file |
convert |
symbol
|
Pass a different byte size, eg kb, mb, gb. See bytes util for more conversion metrics. |
Result
Returns an array of DiskUsage
structs.
DiskUsage Fields
Field | Type | Description |
---|---|---|
fsize |
double
|
Estimated file size of the path. Returned in bytes, if no conversion field passed. |
path |
string
|
Path of where the file size estimation is. |
Return Example
host.su('root')
host.du(path: '/etc').data
[
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x00116e80
fsize = 4,
path = "/etc/ca-certificates/update.d"
>,
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x00116ed0
fsize = 8,
path = "/etc/ca-certificates"
>,
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x00116f20
fsize = 52,
path = "/etc/update-motd.d"
>,
[ 3] .. [219],
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x0011b340
fsize = 36,
path = "/etc/lvm/profile"
>,
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x0011b390
fsize = 144,
path = "/etc/lvm"
>,
#<Struct:Kanrisuru::Core::Disk::DiskUsage:0x0011b3e0
fsize = 5704,
path = "/etc"
>
]
Exit Status
Code | Description |
---|---|
0 | Success |
1 | Failure |
Additional Examples
host.du(path: '/var', summarize: true)[0].fsize
1839768
host.du(path: '/var', summarize: true, convert: :megabyte)[0].fsize
1.8397679999999998
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES