Get available diskspace in ruby

Martin Flucka picture Martin Flucka · Dec 22, 2010 · Viewed 13k times · Source

What is the best way to get diskspace information with ruby. I would prefer a pure ruby solution. If not possible (even with additional gems), it could also use any command available in a standard ubuntu desktop installation to parse the information into ruby.

Answer

dkam picture dkam · May 28, 2011

You could use the sys-filesystem gem (cross platform friendly)

require 'sys/filesystem'

stat = Sys::Filesystem.stat("/")
mb_available = stat.block_size * stat.blocks_available / 1024 / 1024