Subject: less-wide df(1) output
To: None <tech-misc@netbsd.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: tech-misc
Date: 10/05/2002 00:58:41
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.

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

My patch below.

Any comments?

   Jeremy C. Reed
   http://www.reedmedia.net/

--- df.c.orig	Thu Oct 11 09:31:33 2001
+++ df.c	Sat Oct  5 00:54:15 2002
@@ -350,12 +350,15 @@
 			headerlen = strlen(header);
 		} else
 			header = getbsize(&headerlen, &blocksize);
-		(void)printf("%-*.*s %s     Used %9s Capacity",
-		    maxwidth, maxwidth, "Filesystem", header,
-		    Pflag ? "Available" : "Avail");
+		if (Pflag)
+			(void)printf("%-*.*s %s     Used Available Capacity",
+			    maxwidth, maxwidth, "Filesystem", header);
+		else
+			(void)printf("%-*.*s %s     Used     Avail %%Used",
+			    maxwidth, maxwidth, "Filesystem", header);
 		if (iflag)
-			(void)printf(" iused   ifree  %%iused");
-		(void)printf("  Mounted on\n");
+			(void)printf("  iused   ifree %%iused");
+		(void)printf(" Mounted on\n");
 	}
 	(void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
 	used = sfsp->f_blocks - sfsp->f_bfree;
@@ -364,17 +367,19 @@
 	    fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
 	    fsbtoblk(used, sfsp->f_bsize, blocksize),
 	    fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize));
-	(void)printf("%7s",
+	if (Pflag) (void)printf("  ");
+	(void)printf("%5s ",
 	    availblks == 0 ? full : strpct((u_long)used, (u_long)availblks, 0));
+	if (Pflag) (void)printf(" ");
 	if (iflag) {
 		inodes = sfsp->f_files;
 		used = inodes - sfsp->f_ffree;
-		(void)printf(" %7ld %7ld %6s ", used, sfsp->f_ffree,
+		(void)printf("%7ld %7ld %5s  ", used, sfsp->f_ffree,
 		    inodes == 0 ? full :
 		    strpct((u_long)used, (u_long)inodes, 0));
 	} else
-		(void)printf("  ");
-	(void)printf("  %s\n", sfsp->f_mntonname);
+		(void)printf(" ");
+	(void)printf("%s\n", sfsp->f_mntonname);
 }

 /*