Robert Elz <k...@munnari.oz.au> wrote: > Is is the output format which is chosen (by option, or by > using the rule to select the default) which affects what is > output. > > And I believe that the -x and -C variation depending upon how > many columns are output really is a bug, that should just be > fixed.
How about the attached diff? That fixes '-xs' and '-Cs' to print 'total' even if a single-column is all that can be printed. With that: ls -s -> prints 'total' ls -s1 -> does not print 'total' ls -s | cat -> does not print 'total' ls -Cs | cat -> prints 'total' ls -ms -> does not print 'total' ls -xs -> prints 'total' ls -xs | cat -> prints 'total' COLUMNS=1 ls -s -> prints 'total' COLUMNS=1 ls -xs -> prints 'total' -Jan
Index: ls.1 =================================================================== RCS file: /cvsroot/src/bin/ls/ls.1,v retrieving revision 1.81 diff -b -u -r1.81 ls.1 --- ls.1 16 May 2020 18:31:45 -0000 1.81 +++ ls.1 5 Nov 2024 21:41:30 -0000 @@ -225,8 +225,11 @@ .Sx ENVIRONMENT ) where partial units are rounded up to the next integer value. -If the output is to a terminal, a total sum for all the file -sizes is output on a line before the listing. +In multi-column output +.Ns ( Fl C +or +.Fl x Ns ), +a total sum for all the file sizes is output on a line before the listing. .It Fl T When used with the .Fl l Index: print.c =================================================================== RCS file: /cvsroot/src/bin/ls/print.c,v retrieving revision 1.57 diff -b -u -r1.57 print.c --- print.c 17 May 2020 23:34:11 -0000 1.57 +++ print.c 5 Nov 2024 21:41:30 -0000 @@ -231,6 +231,8 @@ colwidth += 1; + printtotal(dp); /* "total: %u\n" */ + if (termwidth < 2 * colwidth) { printscol(dp); return; @@ -262,8 +264,6 @@ if (num % numcols) ++numrows; - printtotal(dp); /* "total: %u\n" */ - for (row = 0; row < numrows; ++row) { for (base = row, chcnt = col = 0; col < numcols; ++col) { chcnt = printaname(array[base], dp->s_inode, @@ -298,6 +298,8 @@ colwidth += 1; + printtotal(dp); /* "total: %u\n" */ + if (termwidth < 2 * colwidth) { printscol(dp); return; @@ -306,8 +308,6 @@ numcols = termwidth / colwidth; colwidth = termwidth / numcols; /* spread out if possible */ - printtotal(dp); /* "total: %u\n" */ - chcnt = col = 0; for (p = dp->list; p; p = p->fts_link) { if (IS_NOPRINT(p))