Get the device name where a file resides
class File class Stat def self.device_name(file) Dir['/dev/*'].inject({}) { |h, v| h.update(File.stat(v).rdev => v) }.values_at(File.stat(file).dev).first || nil end end end