mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-02-18 05:12:15 +02:00
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.
This commit is contained in:
committed by
Jim Meyering
parent
1be4f180f5
commit
2b8ecfa6f1
3
NEWS
3
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.
|
||||
|
||||
|
||||
@@ -10427,7 +10427,9 @@ This option is equivalent to @option{--block-size=1M}.
|
||||
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
|
||||
|
||||
15
src/du.c
15
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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user