File: dfrb

package info (click to toggle)
ruby-filesystem 0.5-5.1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 124 kB
  • ctags: 102
  • sloc: ansic: 441; makefile: 86; ruby: 47
file content (30 lines) | stat: -rwxr-xr-x 672 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/local/bin/ruby

require 'filesystem'

def pct(total, avail)
  (total == 0) ? 0 : (100.0 * avail / total).round
end

FMT = "%-10s %8d %8d  %3d   %8d %8d  %3d"
HDR = "Mount            KB    Avail %free     Files    Avail %free"

def df(mnt)
  puts HDR if mnt.size > 0
  mnt.sort.each do |m|
    s = FileSystem.stat m
    bpct = pct(s.blocks, s.blocks_avail)
    fpct = pct(s.files,  s.files_avail)
    puts format(FMT, m, s.blocks, s.blocks_avail, bpct, 
                        s.files,  s.files_avail,  fpct)
  end
end

def mounted
  mts = []
  FileSystem.mounts.each {|m| mts << m.mount if m.device =~ %r(/dev/)}
  mts
end

df ((ARGV.size == 0) ? mounted : ARGV)