Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 May 2008 14:16:50 GMT
From:      Robert Woolley <freebsd-pr08@mlists.homeunix.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/123418: [patch] Add -g (Gbyte) option to du(1) + manpage cleanup
Message-ID:  <200805051416.m45EGofJ068570@www.freebsd.org>
Resent-Message-ID: <200805051420.m45EK2Hk088733@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         123418
>Category:       bin
>Synopsis:       [patch] Add -g (Gbyte) option to du(1) + manpage cleanup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 05 14:20:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Robert Woolley
>Release:        7.0 with du.1 and du.c from CURRENT
>Organization:
>Environment:
FreeBSD gumby.homeunix.com 7.0-RELEASE-p1 FreeBSD 7.0-RELEASE-p1 #0: Mon May  5 14:19:07 BST 2008     root@gumby.homeunix.com:/usr/obj/usr/src/sys/MUSTARD  i386

>Description:
Patch adds a GByte blocksize option to du(1), bringing it into line with df(1). I find GB units to be preferable for seeing at-a-glance which directories are using significant space.

In adding the -g option to the manpage, I also reordered the options into alphabetical order, since they were in a bit of a mess.
>How-To-Repeat:

>Fix:

Note that the patch is against CURRENT. The changes to du.c from 7.0 to current are self-contained, so I copied du.c and du.1 from CVS into 7.0.



Patch attached with submission follows:

--- usr.bin/du/du.c.orig	2008-04-29 21:38:35.000000000 +0100
+++ usr.bin/du/du.c	2008-04-29 21:42:54.000000000 +0100
@@ -105,7 +105,7 @@
 	depth = INT_MAX;
 	SLIST_INIT(&ignores);
 
-	while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1)
+	while ((ch = getopt(argc, argv, "HI:LPasd:cghklmnrx")) != -1)
 		switch (ch) {
 			case 'H':
 				Hflag = 1;
@@ -141,6 +141,11 @@
 			case 'c':
 				cflag = 1;
 				break;
+                        case 'g':
+                                hflag = 0;
+                                if (setenv("BLOCKSIZE", "1073741824", 1) == -1)
+                                        warn("setenv: cannot set BLOCKSIZE=1073741824");
+                                break;
 			case 'h':
 				if (setenv("BLOCKSIZE", "512", 1) == -1)
 					warn(
@@ -454,7 +459,7 @@
 {
 	(void)fprintf(stderr,
 		"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] "
-		"[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
+		"[-l] [-h | -k | -m | -g] [-n] [-x] [-I mask] [file ...]\n");
 	exit(EX_USAGE);
 }
 
--- usr.bin/du/du.1.orig	2008-04-29 21:38:22.000000000 +0100
+++ usr.bin/du/du.1	2008-05-05 12:57:47.000000000 +0100
@@ -60,41 +60,30 @@
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl a
+Display an entry for each file in a file hierarchy.
+.It Fl c
+Display a grand total.
+.It Fl d Ar depth
+Display an entry for all files and directories
+.Ar depth
+directories deep.
+.It Fl g
+Display block counts in 1073741824-byte (1-Gbyte) blocks.
 .It Fl H
 Symbolic links on the command line are followed, symbolic links in file
 hierarchies are not followed.
-.It Fl L
-Symbolic links on the command line and in file hierarchies are followed.
-.It Fl I Ar mask
-Ignore files and directories matching the specified
-.Ar mask .
-.It Fl P
-No symbolic links are followed.
-This is the default.
-.It Fl a
-Display an entry for each file in a file hierarchy.
 .It Fl h
 "Human-readable" output.
 Use unit suffixes: Byte, Kilobyte, Megabyte,
 Gigabyte, Terabyte and Petabyte.
-.It Fl r
-Generate messages about directories that cannot be read, files
-that cannot be opened, and so on.
-This is the default case.
-This option exists solely for conformance with
-.St -xpg4 .
-.It Fl s
-Display an entry for each specified file.
-(Equivalent to
-.Fl d Li 0 )
-.It Fl d Ar depth
-Display an entry for all files and directories
-.Ar depth
-directories deep.
-.It Fl c
-Display a grand total.
+.It Fl I Ar mask
+Ignore files and directories matching the specified
+.Ar mask .
 .It Fl k
 Display block counts in 1024-byte (1-Kbyte) blocks.
+.It Fl L
+Symbolic links on the command line and in file hierarchies are followed.
 .It Fl l
 If a file has multiple hard links, count its size many times.
 The default behavior of
@@ -112,6 +101,19 @@
 flag
 .Pq Dv UF_NODUMP
 set.
+.It Fl P
+No symbolic links are followed.
+This is the default.
+.It Fl r
+Generate messages about directories that cannot be read, files
+that cannot be opened, and so on.
+This is the default case.
+This option exists solely for conformance with
+.St -xpg4 .
+.It Fl s
+Display an entry for each specified file.
+(Equivalent to
+.Fl d Li 0 )
 .It Fl x
 File system mount points are not traversed.
 .El


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805051416.m45EGofJ068570>