get system total disk space in ruby

You can use the sys/filesystem gem to get system disk space information in Ruby.

Here is an example code snippet that outputs the total capacity of the root directory:

main.rb
require 'sys/filesystem'

stat = Sys::Filesystem.stat("/")
total_space_in_bytes = stat.block_size * stat.blocks

puts "Total capacity of root directory: #{total_space_in_bytes/1024/1024} MB"
191 chars
7 lines

This code snippet requires the sys/filesystem gem. You can install it by running gem install sys-filesystem in your terminal.

gistlibby LogSnag