[comp.unix.aux] BSD-style df emulator

vlb@Apple.COM (Vicki Brown) (11/08/88)

I don't know about other people, but I vastly prefer the BSD style output from
`df' to the System V output.  So I wrote a quick filter to give me what I
want to see.  A friend suggested that I post it, so here it is (no guarantees
made or implied :-).  I don't give quite as much information as BSD's df -i
(I'll leave that as an exercise to those who care.)  And I changed "capacity"
to "%used" because it made more sense to me.  Enjoy.

==================================== cut here ================================
:
: df4.2
:
# written by Vicki Brown, April 1987
# emulate the BSD style df under A/UX

#  Turns this:

# /         /dev/dsk/c0d0s0          4114 blocks    8489 i-nodes
#                          total   111184 blocks   13888 i-nodes
# /src      /dev/dsk/c6d0s0         35372 blocks    7685 i-nodes
#                          total    74322 blocks    9280 i-nodes

# Into this:

# Filesystem        kbytes    used   avail %used %iused   Mounted on
# /dev/dsk/c0d0s0    55592   53534    2058   96%    38%   /           
# /dev/dsk/c6d0s0    37161   19475   17686   52%    17%   /src        


/bin/df -t $* |
awk '
BEGIN {
	# blocksize = 512 bytes (one half kbyte)
	printf("Filesystem%10skbytes    used   avail %%used ", " ")
	printf("%%iused   Mounted on\n")
}
$1 == "total" {
	kbytes = $2/2
	used = kbytes - avail
	capac = (used/kbytes)*100
        if ($4 != 0)
	  iused = 100-(ifree/$4)*100
	else
	  iused = 0

	printf("%-18s %7d %7d %7d %4d%% %5d%%   %-18s\n", \
	  dev, kbytes, used, avail, capac, iused, dir)
	next
}
{
	dir = $1
	dev = $2

	blocks = $3		# free blocks
	ifree = $5 		# free inodes
	avail = blocks/2
}
'
Vicki Brown			(408) 974-2120
A/UX Engineering		vicki@apple.com

(opinions?  These aren't opinions; these are facts!)