List all hard drives on system (with capacities)... How?

James james at hicag.org
Fri Dec 7 06:54:58 UTC 2012


And because I think geom(8) and awk(1) are awesome...

geom disk list | awk '
BEGIN { FS=": *" }
$1 == "Geom name" { device=$2 }
$1 ~ "^ +Mediasize$" {
	match($2, /\([^)]+\)/)
	size=substr($2, RSTART+1, RLENGTH-2)
}
$1 ~ "^ +descr$" {
	if ($2 == "(null)") {
		descr="UNKNOWN"
	} else {
		descr=$2
		gsub(/ /, "_", descr)
	}
}
/^$/ {
	if (device !~ /^cd[0-9]+/) {
		printf "%s %s %s\n", device, size, descr
	}
}
'

This likely won't handle every possible device type available.
Something very similar is serving me well thus far.

HTH!

-- 
James.


More information about the freebsd-questions mailing list