GNU bug report logs -
#6186
du in coreutils should add the -d flag as a shortcut to --max-depth
Previous Next
Reported by: Jon Ringuette <jonr <at> scharp.org>
Date: Thu, 13 May 2010 18:49:01 UTC
Severity: normal
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6186 in the body.
You can then email your comments to 6186 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, help-debbugs <at> gnu.org
:
bug#6186
; Package
debbugs.gnu.org
.
(Thu, 13 May 2010 18:49:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jon Ringuette <jonr <at> scharp.org>
:
New bug report received and forwarded. Copy sent to
help-debbugs <at> gnu.org
.
(Thu, 13 May 2010 18:49:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Package : coreutils
Version : All
Command : du
Type : Feature Request
Hello,
In the FreeBSD world it is common to have a short argument of '-d' for --max-depth. This greatly shortens a command one must type to when a depth argument is used (which from my experience is often).
For example currently to say get the size of all the home directories of users one would use : du /home -h --max-depth=1 . It would make life simpler and make going from FreeBSD systems to Linux systems easier for people and scripts if the syntax : du /home -h -d 1 was also supposed.
Thank you,
--
Jon Ringuette
SCHARP/FHCRC
1100 Fairview ave. N LE-400
Office: Phone: 206.667.6378 Mobile: 206.659.5660 Fax: 206.667.4812
E-mail: jonr <at> scharp.org
CONFIDENTIALITY NOTICE: This e-mail message and any attachments may be confidential and privileged. If you are not intended to receive this
message, please notify the sender and destroy the message. Thank you.
[Message part 2 (text/html, inline)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Thu, 13 May 2010 19:20:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 6186 <at> debbugs.gnu.org (full text, mbox):
[ The following went to the help-debbugs list, I think because putting
a space before the ':' in the pseudo-headers does not work. I am
resending it so that it goes to the bug-coreutils list. Note that
"Command" and "Type" are not recognized pseudo-headers. You don't need
to worry about any of this, but if interested see
http://debbugs.gnu.org/Reporting.html ]
From: Jon Ringuette <jonr <at> scharp.org>
To: submit <at> debbugs.gnu.org
Package : coreutils
Version : All
Command : du
Type : Feature Request
Hello,
In the FreeBSD world it is common to have a short argument of '-d' for
--max-depth. This greatly shortens a command one must type to when a
depth argument is used (which from my experience is often).
For example currently to say get the size of all the home directories
of users one would use : du /home -h --max-depth=1 . It would make
life simpler and make going from FreeBSD systems to Linux systems
easier for people and scripts if the syntax : du /home -h -d 1 was
also supposed.
Thank you,
--
Jon Ringuette
SCHARP/FHCRC
1100 Fairview ave. N LE-400
Office: Phone: 206.667.6378 Mobile: 206.659.5660 Fax: 206.667.4812
E-mail: jonr <at> scharp.org
CONFIDENTIALITY NOTICE: This e-mail message and any attachments may be confidential and privileged. If you are not intended to receive this
message, please notify the sender and destroy the message. Thank you.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Thu, 13 May 2010 19:33:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 6186 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 05/13/2010 01:19 PM, Jon Ringuette wrote:
> For example currently to say get the size of all the home directories
> of users one would use : du /home -h --max-depth=1 . It would make
> life simpler and make going from FreeBSD systems to Linux systems
> easier for people and scripts if the syntax : du /home -h -d 1 was
> also supposed.
Prior practice is always a good reason to support changes like this. It
would be a very simple patch to du.c to convert --max-depth from
long-option only to also having a short-option equivalent. Would you
like to try your hand at it first?
If not, I can probably get around to this in another day or two.
--
Eric Blake eblake <at> redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Thu, 13 May 2010 19:48:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 6186 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thank you for considering my request. I'll put a patch together for submission.
--
Jon Ringuette
SCHARP/FHCRC
1100 Fairview ave. N LE-400
Office: Phone: 206.667.6378 Mobile: 206.659.5660 Fax: 206.667.4812
E-mail: jonr <at> scharp.org
CONFIDENTIALITY NOTICE: This e-mail message and any attachments may be confidential and privileged. If you are not intended to receive this
message, please notify the sender and destroy the message. Thank you.
On May 13, 2010, at 12:31 PM, Eric Blake wrote:
> On 05/13/2010 01:19 PM, Jon Ringuette wrote:
>> For example currently to say get the size of all the home directories
>> of users one would use : du /home -h --max-depth=1 . It would make
>> life simpler and make going from FreeBSD systems to Linux systems
>> easier for people and scripts if the syntax : du /home -h -d 1 was
>> also supposed.
>
> Prior practice is always a good reason to support changes like this. It
> would be a very simple patch to du.c to convert --max-depth from
> long-option only to also having a short-option equivalent. Would you
> like to try your hand at it first?
>
> If not, I can probably get around to this in another day or two.
>
> --
> Eric Blake eblake <at> redhat.com +1-801-349-2682
> Libvirt virtualization library http://libvirt.org
>
[Message part 2 (text/html, inline)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Thu, 13 May 2010 23:40:03 GMT)
Full text and
rfc822 format available.
Message #17 received at 6186 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
So here is my first whack at it. One thing to note is there was a DU_DEBUG optional define that defined a -d flag to use for debugging. It seemed like using -d would be more useful for everyone to use for depth then for debug so I modified the slightly oddly thrown in debug stuff to now work with --debug instead. Though when I actually define DU_DEBUG so the #if DU_DEBUG is picked up and used it complains about the function missing so I'm kind of curios if this has worked for awhile.
Anyways any feedback or recommendations would be greatly appreciated so this has a better chance of making its way into the release.
Thank you for your time on this matter!
--
Jon Ringuette
SCHARP/FHCRC
On May 13, 2010, at 12:31 PM, Eric Blake wrote:
> On 05/13/2010 01:19 PM, Jon Ringuette wrote:
>> For example currently to say get the size of all the home directories
>> of users one would use : du /home -h --max-depth=1 . It would make
>> life simpler and make going from FreeBSD systems to Linux systems
>> easier for people and scripts if the syntax : du /home -h -d 1 was
>> also supposed.
>
> Prior practice is always a good reason to support changes like this. It
> would be a very simple patch to du.c to convert --max-depth from
> long-option only to also having a short-option equivalent. Would you
> like to try your hand at it first?
>
> If not, I can probably get around to this in another day or two.
>
> --
> Eric Blake eblake <at> redhat.com +1-801-349-2682
> Libvirt virtualization library http://libvirt.org
>
[Message part 2 (text/html, inline)]
[du_add_d.patch (application/octet-stream, attachment)]
[Message part 4 (text/html, inline)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Fri, 14 May 2010 08:07:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 6186 <at> debbugs.gnu.org (full text, mbox):
Jon Ringuette wrote:
> So here is my first whack at it. One thing to note is there was a DU_DEBUG optional define that defined a -d flag to use for debugging. It seemed like using -d would be more useful for everyone to use for depth then for debug so I modified the slightly oddly thrown in debug stuff to now work with --debug instead. Though when I actually define DU_DEBUG so the #if DU_DEBUG is picked up and used it complains about the function missing so I'm kind of curios if this has worked for awhile.
Moving debug functionality to --debug is fine.
Since it's compiled out and I haven't made an effort
to enable it otherwise, it hasn't kept pace with other
changes. No big deal. However, it was essential during
the last round of big changes, so I'm not ready to remove
it altogether just yet.
> Anyways any feedback or recommendations would be greatly appreciated so this has a better chance of making its way into the release.
>
> Thank you for your time on this matter!
Your patch did not reach the list.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Mon, 17 May 2010 21:15:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 6186 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I believe it shows up as an attachment on the http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6186 with my last email : [du_add_d.patch (application/octet-stream, attachment)]
I can also post the patch directly instead of as a file attachment if that is easier.
Just doing a normal #define DU_DEBUG 1 was giving me an error about lower case function fts_cross_check not existing. Is there a better way for me to test this to ensure my modification of the debug flag to --debug did not negatively impact past work?
thanks!
-jon
On May 14, 2010, at 1:06 AM, Jim Meyering wrote:
> Jon Ringuette wrote:
>> So here is my first whack at it. One thing to note is there was a DU_DEBUG optional define that defined a -d flag to use for debugging. It seemed like using -d would be more useful for everyone to use for depth then for debug so I modified the slightly oddly thrown in debug stuff to now work with --debug instead. Though when I actually define DU_DEBUG so the #if DU_DEBUG is picked up and used it complains about the function missing so I'm kind of curios if this has worked for awhile.
>
> Moving debug functionality to --debug is fine.
> Since it's compiled out and I haven't made an effort
> to enable it otherwise, it hasn't kept pace with other
> changes. No big deal. However, it was essential during
> the last round of big changes, so I'm not ready to remove
> it altogether just yet.
>
>> Anyways any feedback or recommendations would be greatly appreciated so this has a better chance of making its way into the release.
>>
>> Thank you for your time on this matter!
>
> Your patch did not reach the list.
[Message part 2 (text/html, inline)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6186
; Package
coreutils
.
(Tue, 18 May 2010 06:57:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 6186 <at> debbugs.gnu.org (full text, mbox):
Jon Ringuette wrote:
...
>> Your patch did not reach the list.
> I believe it shows up as an attachment on the http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6186 with my last email : [du_add_d.patch (application/octet-stream, attachment)]
I had not seen that.
Besides, that is not the mailing list ;-)
> I can also post the patch directly instead of as a file attachment if that is easier.
>
> Just doing a normal #define DU_DEBUG 1 was giving me an error about lower case function fts_cross_check not existing. Is there a better way for me to test this to ensure my modification of the debug flag to --debug did not negatively impact past work?
I was going to request this:
Please do post to the list.
However, a few guidelines:
- post git format-patch output, not diff -c output
- please update NEWS with a sentence describing your change
- also update doc/coreutils.texi (that's the primary documentation)
- change/extend a test to exercise the new option
(hmm... no test exercises --max-depth=N, so asking you to do
this isn't really fair)
If you're not familiar with git, a quick how-to is
in readme files. Start with README-hacking to checkout the sources,
then read the first few paragraphs of HACKING for instructions
on setting up and using git.
but I've decided to do it all for you, and
in so doing discovered one part that has to be changed:
we can't introduce the --debug option your patch adds,
since that shares a prefix with --dereference-args.
Currently, both --d and --de serve as abbreviations for that long-named
option. If we were to add --debug, they would become ambiguous and make
those uses stop working. Besides, --debug can't do anything unless
gnulib's fts.c is compiled with debugging enabled.
Eventually, or while debugging, I may add the three-hyphen ---debug
option, but for now have simply commented that out.
I've added a test for --max-depth=N, then wrote the commit log,
NEWS, .texi and test changes to go with your code patch.
-------------------------------
From a1b74559f1b0dc60b866fa9c0220096fa4abffeb Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering <at> redhat.com>
Date: Tue, 18 May 2010 08:39:40 +0200
Subject: [PATCH 1/2] tests: exercise du's --max-depth option
* tests/Makefile.am (TESTS): Add du/max-depth.
* tests/du/max-depth: New file.
---
tests/Makefile.am | 1 +
tests/du/max-depth | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)
create mode 100755 tests/du/max-depth
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a732c63..c458574 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -350,6 +350,7 @@ TESTS = \
du/inaccessible-cwd \
du/long-from-unreadable \
du/long-sloop \
+ du/max-depth \
du/no-deref \
du/no-x \
du/one-file-system \
diff --git a/tests/du/max-depth b/tests/du/max-depth
new file mode 100755
index 0000000..4ddb6b7
--- /dev/null
+++ b/tests/du/max-depth
@@ -0,0 +1,31 @@
+#!/bin/sh
+# exercise du's --max-depth=N option
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+mkdir -p a/b/c/d/e || framework_failure_
+printf 'a/b/c\na/b\na\n' > exp || framework_failure_
+
+du --max-depth=2 a > out 2>err || fail=1
+
+# Remove the sizes. They vary between file systems.
+cut -f2- out > k && mv k out
+compare out exp || fail=1
+compare err /dev/null || fail=1
+
+Exit $fail
--
1.7.1.250.g7d1e8
From 1ccacf7a1b5b93f9e4c8ef562ceceab9726f8656 Mon Sep 17 00:00:00 2001
From: Jon Ringuette <jonr <at> scharp.org>
Date: Tue, 18 May 2010 08:26:11 +0200
Subject: [PATCH 2/2] du: recognize -d N as equivalent to --max-depth=N
* NEWS (New features): Mention it.
* src/du.c (DEBUG_OPT): Remove. Use long-named ---debug instead.
Commented out.
(MAX_DEPTH_OPTION): Remove. Use 'd' instead.
(main): Insert literal "d:"; remove DEBUG_OPT.
* doc/coreutils.texi (du invocation): Add -d to indices.
* tests/du/max-depth: Exercise -d, too.
---
NEWS | 3 +++
doc/coreutils.texi | 2 ++
src/du.c | 15 +++++++--------
tests/du/max-depth | 7 +++++++
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/NEWS b/NEWS
index 5d7b81f..19436fe 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*-
** New features
+ du recognizes -d N as equivalent to --max-depth=N, for compatibility
+ with FreeBSD.
+
sort now accepts the --debug option, to highlight the part of the
line significant in the sort, and warn about questionable options.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 77434e9..115e5fb 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10427,7 +10427,9 @@ du invocation
For each symbolic links encountered by @command{du},
consider the disk space used by the symbolic link.
+@item -d @var{depth}
@item --max-depth=@var{depth}
+@opindex -d @var{depth}
@opindex --max-depth=@var{depth}
@cindex limiting output of @command{du}
Show the total for each directory (and file if --all) that is at
diff --git a/src/du.c b/src/du.c
index 907ad79..5d83dc6 100644
--- a/src/du.c
+++ b/src/du.c
@@ -56,10 +56,8 @@ extern bool fts_debug;
#if DU_DEBUG
# define FTS_CROSS_CHECK(Fts) fts_cross_check (Fts)
-# define DEBUG_OPT "d"
#else
# define FTS_CROSS_CHECK(Fts)
-# define DEBUG_OPT
#endif
/* Initial size of the hash table. */
@@ -192,7 +190,7 @@ enum
EXCLUDE_OPTION,
FILES0_FROM_OPTION,
HUMAN_SI_OPTION,
- MAX_DEPTH_OPTION,
+ FTS_DEBUG,
TIME_OPTION,
TIME_STYLE_OPTION
};
@@ -204,6 +202,7 @@ static struct option const long_options[] =
{"block-size", required_argument, NULL, 'B'},
{"bytes", no_argument, NULL, 'b'},
{"count-links", no_argument, NULL, 'l'},
+ /* {"-debug", no_argument, NULL, FTS_DEBUG}, */
{"dereference", no_argument, NULL, 'L'},
{"dereference-args", no_argument, NULL, 'D'},
{"exclude", required_argument, NULL, EXCLUDE_OPTION},
@@ -211,7 +210,7 @@ static struct option const long_options[] =
{"files0-from", required_argument, NULL, FILES0_FROM_OPTION},
{"human-readable", no_argument, NULL, 'h'},
{"si", no_argument, NULL, HUMAN_SI_OPTION},
- {"max-depth", required_argument, NULL, MAX_DEPTH_OPTION},
+ {"max-depth", required_argument, NULL, 'd'},
{"null", no_argument, NULL, '0'},
{"no-dereference", no_argument, NULL, 'P'},
{"one-file-system", no_argument, NULL, 'x'},
@@ -312,7 +311,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
-x, --one-file-system skip directories on different file systems\n\
-X, --exclude-from=FILE exclude files that match any pattern in FILE\n\
--exclude=PATTERN exclude files that match PATTERN\n\
- --max-depth=N print the total for a directory (or file, with --all)\n\
+ -d, --max-depth=N print the total for a directory (or file, with --all)\n\
only if it is N or fewer levels below the command\n\
line argument; --max-depth=0 is the same as\n\
--summarize\n\
@@ -694,7 +693,7 @@ main (int argc, char **argv)
for (;;)
{
int oi = -1;
- int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
+ int c = getopt_long (argc, argv, "0abd:chHklmsxB:DLPSX:",
long_options, &oi);
if (c == -1)
break;
@@ -702,7 +701,7 @@ main (int argc, char **argv)
switch (c)
{
#if DU_DEBUG
- case 'd':
+ case FTS_DEBUG:
fts_debug = true;
break;
#endif
@@ -744,7 +743,7 @@ main (int argc, char **argv)
output_block_size = 1024;
break;
- case MAX_DEPTH_OPTION: /* --max-depth=N */
+ case 'd': /* --max-depth=N */
{
unsigned long int tmp_ulong;
if (xstrtoul (optarg, NULL, 0, &tmp_ulong, NULL) == LONGINT_OK
diff --git a/tests/du/max-depth b/tests/du/max-depth
index 4ddb6b7..ec22989 100755
--- a/tests/du/max-depth
+++ b/tests/du/max-depth
@@ -28,4 +28,11 @@ cut -f2- out > k && mv k out
compare out exp || fail=1
compare err /dev/null || fail=1
+# Repeat, but use -d 1.
+printf 'a/b\na\n' > exp || framework_failure_
+du -d 1 a > out 2>err || fail=1
+cut -f2- out > k && mv k out
+compare out exp || fail=1
+compare err /dev/null || fail=1
+
Exit $fail
--
1.7.1.250.g7d1e8
Reply sent
to
Jim Meyering <jim <at> meyering.net>
:
You have taken responsibility.
(Wed, 19 May 2010 07:18:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Jon Ringuette <jonr <at> scharp.org>
:
bug acknowledged by developer.
(Wed, 19 May 2010 07:18:02 GMT)
Full text and
rfc822 format available.
Message #31 received at 6186-done <at> debbugs.gnu.org (full text, mbox):
Jim Meyering wrote:
...
>>From a1b74559f1b0dc60b866fa9c0220096fa4abffeb Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering <at> redhat.com>
> Date: Tue, 18 May 2010 08:39:40 +0200
> Subject: [PATCH 1/2] tests: exercise du's --max-depth option
>
> * tests/Makefile.am (TESTS): Add du/max-depth.
> * tests/du/max-depth: New file.
...
>>From 1ccacf7a1b5b93f9e4c8ef562ceceab9726f8656 Mon Sep 17 00:00:00 2001
> From: Jon Ringuette <jonr <at> scharp.org>
> Date: Tue, 18 May 2010 08:26:11 +0200
> Subject: [PATCH 2/2] du: recognize -d N as equivalent to --max-depth=N
>
> * NEWS (New features): Mention it.
> * src/du.c (DEBUG_OPT): Remove. Use long-named ---debug instead.
> Commented out.
> (MAX_DEPTH_OPTION): Remove. Use 'd' instead.
> (main): Insert literal "d:"; remove DEBUG_OPT.
> * doc/coreutils.texi (du invocation): Add -d to indices.
> * tests/du/max-depth: Exercise -d, too.
> ---
> NEWS | 3 +++
> doc/coreutils.texi | 2 ++
> src/du.c | 15 +++++++--------
> tests/du/max-depth | 7 +++++++
> 4 files changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index 5d7b81f..19436fe 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*-
>
> ** New features
>
> + du recognizes -d N as equivalent to --max-depth=N, for compatibility
> + with FreeBSD.
I've pushed those two change sets.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 16 Jun 2010 11:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 15 years and 64 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.