[ILUG] ugly df
Brian Foster
blf at blf.utvinternet.ie
Sat Nov 11 06:36:19 GMT 2006
| Date: Sat, 11 Nov 2006 07:51:20 +0900
| From: "Josh Glover" <jmglov at wmalumni.com>
|
| On 11/11/06, Paul Reilly <paulr at maths.tcd.ie> wrote:
| > Anyone know a simple way to make df display it's output nicely?
|
| Sure. This fact that I call df twice is slightly garbage, but it gets
| the job done and I cannot think of another way to not sort the first
| line, short of using a tmp file.
|
| df -h | head -1; df -h | sed -e 1d | sort
sorry, I couldn't resist the challenge to run df(1)
just once ....
(df -h | sed -e '1{w/dev/fd/3
d;}' | sort -nk 1.9 ) 3>&1
Filesystem Size Used Avail Use% Mounted on
/dev/hdb1 1012M 38M 923M 4% /boot
/dev/hda4 23G 20G 2.8G 88% /a/hda4
/dev/hdb5 21G 4.4G 16G 22% /opt
/dev/hdb6 10G 2.1G 8.0G 21% /var
/dev/hdb7 6.1G 171M 5.9G 3% /
/dev/hdb9 11G 202M 9.9G 2% /tmp
/dev/hdb10 25G 11G 14G 45% /usr
/dev/hdb11 41G 18G 23G 45% /home
/dev/hdb12 41G 41G 571M 99% /a
tmpfs 126M 12K 126M 1% /dev/shm
this is not too general, does not do everything Paul
wants (IIRC), has a race condition, and does not deal
with multiple drives too well (as you can see in the
above output), but does run `df' only once. ;-)
the embedded newline seems to be mandatory. ;-(
except for the race condition, Josh's double-`df' has
similar, but not identical, limitations.
switching the tools used slightly (awk(1) is, in this
case, possibly a better choice than sed(1)?) can be
used to remove most(/all?) of these limitations.
cheers!
-blf-
--
Experienced (20+ yrs) kernel/software Eng: | Brian Foster Montpellier,
• Unix, embedded, &tc; • Linux; • doc; | blf at utvinternet.ie FRANCE
• IDL, automated testing, process, &tc. | Stop E$$o (ExxonMobile)!
Résumé (CV) http://www.blf.utvinternet.ie | http://www.stopesso.com
More information about the ILUG
mailing list