[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: The ls command



On 2025-10-30 at 18:54, Nicolas George wrote:

> Greg Wooledge (HE12025-10-30):
> 
>> I think we're getting lost in the terminology.  When the output of
>> ls is a pipe, ls writes one filename per line.  The output is
>> therefore a single column.
> 
> When the output of ls is not a tty (for example, a pipe), it does
> not format columns, plural. Of course, if it does not format columns,
> the output will appear as a single column.

While I get what you're saying, and it does make sense, it's not as "of
course" as you might think; there is at least one other possible output
form, which is even less formatted than the "single column" version.

I thought it was hypothetical, and had written up an example with that
as the basis, but it turns out that a variant of it actually exists in
ls as implemented (at least the version I have installed).

Try

$ ls -m

or

$ ls --format=commas

sometime, in a terminal large enough to have supported multiple columns.
Unless the filenames happen to be all the exact same length (or there
are few enough to be able to fit on a single line), the result will
certainly not be columnar, whether one column or multiple.

(This is, of course, a frivolous side path. But at the very least, it
has led me to learn something new today.)

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man.         -- George Bernard Shaw

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: