From: Collin Funk Date: Fri, 28 Nov 2025 05:33:30 +0000 (-0800) Subject: du: add the short option -A corresponding to --apparent-size X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=90856dd867ba7a86a0a54e987048b0250b716c3b;p=thirdparty%2Fcoreutils.git du: add the short option -A corresponding to --apparent-size The --apparent-size option to 'du' was added in coreutils-4.5.8 (2003). FreeBSD 8.0 (2009) added the same functionality under the short option -A. This long option previously had no short option, so this patch adds -A to be compatible with FreeBSD. * NEWS: Mention the new short option. * doc/coreutils.texi: Document the short option. * src/du.c (usage): Likewise. (APPARENT_SIZE_OPTION): Remove definition. (EXCLUDE_OPTION): Define to CHAR_MAX + 1. (long_options): Use the -A short option for --apparent-size. (main): Likewise. * tests/du/apparent.sh: Test that '-b', '-A -B 1', and '--apparent-size --block-size 1' function the same. --- diff --git a/NEWS b/NEWS index 019451d32e..2319e45175 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,9 @@ GNU coreutils NEWS -*- outline -*- 'tail' now accepts the --debug option, which is currently used to detail the --follow implementation being used. + 'du' now supports the short option -A corresponding to the existing long + option --apparent-size, for compatibility with FreeBSD. + ** Changes in behavior 'timeout' now honors ignored signals and will not propagate them. E.g., diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 098fa4761a..5836862120 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -12755,7 +12755,9 @@ The program accepts the following options. Also see @ref{Common options}. @opindex --all Show counts for all files, not just directories. -@item --apparent-size +@item -A +@itemx --apparent-size +@opindex -A @opindex --apparent-size Print apparent sizes, rather than file system usage. The apparent size of a file is the number of bytes reported by @code{wc -c} on regular files, diff --git a/src/du.c b/src/du.c index 80d0b53d16..14aa0d652c 100644 --- a/src/du.c +++ b/src/du.c @@ -195,8 +195,7 @@ static struct duinfo tot_dui; non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum { - APPARENT_SIZE_OPTION = CHAR_MAX + 1, - EXCLUDE_OPTION, + EXCLUDE_OPTION = CHAR_MAX + 1, FILES0_FROM_OPTION, HUMAN_SI_OPTION, #if GNULIB_FTS_DEBUG @@ -210,7 +209,7 @@ enum static struct option const long_options[] = { {"all", no_argument, nullptr, 'a'}, - {"apparent-size", no_argument, nullptr, APPARENT_SIZE_OPTION}, + {"apparent-size", no_argument, nullptr, 'A'}, {"block-size", required_argument, nullptr, 'B'}, {"bytes", no_argument, nullptr, 'b'}, {"count-links", no_argument, nullptr, 'l'}, @@ -290,7 +289,7 @@ Summarize device usage of the set of FILEs, recursively for directories.\n\ fputs (_("\ -0, --null end each output line with NUL, not newline\n\ -a, --all write counts for all files, not just directories\n\ - --apparent-size print apparent sizes rather than device usage; although\ + -A, --apparent-size print apparent sizes rather than device usage; although\ \n\ the apparent size is usually smaller, it may be\n\ larger due to holes in ('sparse') files, internal\n\ @@ -745,7 +744,7 @@ main (int argc, char **argv) while (true) { int oi = -1; - int c = getopt_long (argc, argv, "0abd:chHklmst:xB:DLPSX:", + int c = getopt_long (argc, argv, "0aAbd:chHklmst:xB:DLPSX:", long_options, &oi); if (c == -1) break; @@ -766,7 +765,7 @@ main (int argc, char **argv) opt_all = true; break; - case APPARENT_SIZE_OPTION: + case 'A': apparent_size = true; break; diff --git a/tests/du/apparent.sh b/tests/du/apparent.sh index 4a1064fc66..43179736f2 100755 --- a/tests/du/apparent.sh +++ b/tests/du/apparent.sh @@ -24,10 +24,13 @@ for f in $(seq 100); do echo foo >d/$f || framework_failure_ done -du -b d/* >separate || fail=1 -du -b d >together || fail=1 -separate_sum=$($AWK '{sum+=$1}END{print sum}' separate) || framework_failure_ -together_sum=$($AWK '{sum+=$1}END{print sum}' together) || framework_failure_ -test $separate_sum -eq $together_sum || fail=1 +# Check that the following options are equivalent. +for opts in '-b' '-A -B 1' '--apparent-size --block-size 1'; do + du $opts d/* >separate || fail=1 + du $opts d >together || fail=1 + separate_sum=$($AWK '{sum+=$1}END{print sum}' separate) || framework_failure_ + together_sum=$($AWK '{sum+=$1}END{print sum}' together) || framework_failure_ + test $separate_sum -eq $together_sum || fail=1 +done Exit $fail