Subject: Re: less-wide df(1) output
To: Jeremy C. Reed <reed@reedmedia.net>
From: Greg A. Woods <woods@weird.com>
List: tech-misc
Date: 10/05/2002 13:39:22
[ On Saturday, October 5, 2002 at 00:58:41 (-0700), Jeremy C. Reed wrote: ]
> Subject: less-wide df(1) output
>
> What do you think of the following?
> 
> $ ./df -i
> Filesystem  512-blocks     Used     Avail %Used  iused   ifree %iused Mounted on
> /dev/wd0a       295618    61082    219754  21%    3013   34425    8%  /
> /dev/wd0e     11508272  1594582   9338276  14%   62886 1383128    4%  /usr
> 
> It saves a few characters and doesn't wrap (standard 80 characters).
> This could make it more readable in daily report, for example.

I've been meaning to send my patch for this fix for a very long time
now (but someone keeps munging df making me re-merge my changes! :-).

I decided long ago that wasting field space because the header was wider
than the data could ever be was too annoying not to fix.

Whether it wraps on an 80-char display still depends on how long your
filesytem mount point names are of course (and perhaps the device names
too, though as you see below the field headers can overlap just so long
as there's one space between.

You can save at least two more characters by using '%Cap' and '%iCap'
(for "Capacity") instead:

13:24 [967] $ df -kli
Filesystem 1K-blocks     Used    Avail %Cap   iUsed iAvail %iCap Mounted on
/dev/sd0a     490591   276416   189645  59%   14038  109864  11% /
/dev/sd0e     490591   255596   210465  54%   12149  111753   9% /var
/dev/sd1f    2834732  1414906  1278089  52%   34774  677672   4% /opt
/dev/sd1a     490591   144576   321485  31%   10728  113174   8% /altroot
/dev/sd3h    3796798   831404  2775554  23%      12  962546   0% /backups
/dev/sd1e     490591    85675   380386  18%      59  123843   0% /var/NetBSD-release
/dev/sd0f    2834732  1966837   726158  73%  183374  529072  25% /ocvs
/dev/sd5c   12186596  4213260  7364006  36%  370364 2677058  12% /cvs
/dev/sd2h    3815222  2013016  1611444  55%   89541  870713   9% /var/obj
/dev/sd4c   12186596  5810152  5767114  50%  756308 2291114  24% /work
/dev/raid0a 21879470 10651664 10790216  49%  600556 2145298  21% /home
mfs:130       247703      260   235057   0%       9   63285   0% /tmp
kernfs             1        1        0 100%       0       0 100% /kern
procfs             4        4        0 100%     147    3969   3% /proc
fdesc              1        1        0 100%       4      61   6% /fdesc


I didn't quite get to the point of eliminating the extra space after the
%Cap field when '-i' is given, but it shouldn't be too hard to do....


> Plus with -P switch get near old behavior:
> 
> $ ./df -iP
> Filesystem  512-blocks     Used Available Capacity  iused   ifree %iused Mounted on
> /dev/wd0a       295618    61082    219754    21%     3013   34425    8%  /
> /dev/wd0e     11508272  1594582   9338276    14%    62886 1383128    4%  /usr

That's not conformant with P1003.2a in two ways.  First of '-P' and '-i'
are non-standard extensions, and secondly only a single space is allowed
between fields in '-P' output.  This from P1003.2a-draft#8:

 PART 2: SHELL AND UTILITIES -- Amd. 1: UPE                    P1003.2a/D8
 
 5.8.6.1  Standard Output

 When both the -k and -P options are specified, the following header line
 shall be written (in the POSIX Locale):

       "Filesystem 1024-blocks Used Available Capacity Mounted on\n"

 When the -P option is specified without the -k option, the following
 header line shall be written (in the POSIX Locale):

       "Filesystem 512-blocks Used Available Capacity Mounted on\n"

 The implementation may adjust the spacing of the header line and the
 individual data lines so that the information is presented in orderly
 columns.

 The remaining output with -P shall consist of one line of information for
 each specified file system.  These lines shall be formatted as follows:

       "%s %d %d %d %d%% %s\n", <file system name>, <total space>,
       <space used>, <space free>, <percentage used>,
       <file system root>

 In the following list, all quantities expressed in 512-byte units (1024-
 byte when -k is specified) shall be rounded up to the next higher unit.
 The fields are:

    <file system name> The name of the file system, in an implementation-
                       defined format.

    <total space>      The total size of the file system in 512-byte
                       units.  The exact meaning of this figure is
                       implementation defined, but should include
                       <space used>, <space free>, plus any space reserved
                       by the system not normally available to a user.

    <space used>       The total amount of space allocated to existing
                       files in the file system, in 512-byte units.

    <space free>       The total amount of space available within the file
                       system for the creation of new files by
                       unprivileged users, in 512-byte units.  When this
                       figure is less than or equal to zero, it shall not
                       be possible to create any new files on the file
                       system without first deleting others, unless the
                       process has appropriate privileges.  The figure
                       written may be less than zero.

    <percentage used>  The percentage of the normally available space that
                       is currently allocated to all files on the file
                       system.  This shall be calculated using the
                       fraction

                             <space used>/(<space used>+<space free>)

                       expressed as a percentage.  This percentage may be
                       greater than 100 if <space free> is less than zero.
                       The percentage value shall be expressed as a
                       positive integer, with any fractional result
                       causing it to be rounded to the next highest
                       integer.

    <file system root> The directory below which the file system hierarchy
                       appears.


I don't have any problem with adding '-i' as a non-standard extention
to '-P', of course, but my patches currently throw an error:

	$ df -iP
	df: only one of -i and -P may be specified

	$ df -Pl
	Filesystem 512-blocks Used Available Capacity Mounted on
	/dev/sd0a 981182 552832 379290 59% /
	/dev/sd0e 981182 511396 420726 54% /var
	/dev/sd1f 5669464 2829812 2556178 52% /opt
	/dev/sd1a 981182 289152 642970 31% /altroot
	/dev/sd3h 7593596 1662808 5551108 23% /backups
	/dev/sd1e 981182 171350 760772 18% /var/NetBSD-release
	/dev/sd0f 5669464 3933674 1452316 73% /ocvs
	/dev/sd5c 24373192 8426520 14728012 36% /cvs
	/dev/sd2h 7630444 2236356 5012564 30% /var/obj
	/dev/sd4c 24373192 11620304 11534228 50% /work
	/dev/raid0a 43758940 21303364 21580396 49% /home
	mfs:130 495406 520 470114 0% /tmp
	kernfs 2 2 0 100% /kern
	procfs 8 8 0 100% /proc
	fdesc 2 2 0 100% /fdesc

-- 
								Greg A. Woods

+1 416 218-0098;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>