Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1597740 - ls -C vs ls -1 vs ls
Summary: ls -C vs ls -1 vs ls
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: coreutils
Version: 7.5
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Kamil Dudka
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-07-03 14:35 UTC by D. E. Evans
Modified: 2018-07-08 21:09 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-07-03 15:45:54 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description D. E. Evans 2018-07-03 14:35:33 UTC
On at least RHEL 5-7, the ls command defaults to a weird mix of columnized and non-columnized output. On every other Unix system I've worked on, ls defaults to the equivalent of -1, at least on a pipe. GNU coreutils default to -C interactively, but -1 non-interactively (e.g. a pipe). I don't see this behavior upstream, so it appears to be unique to RHEL, (I haven't verified on Fedora).

Notice the odd results (RHEL 5.11):

# ls | wc -l
8
# ls -C | wc -l
8
# ls -1 | wc -l
22

This is from RHEL 7.5 (in this case mostly directories):

# ls | wc
     29      86    1331
# ls -C | wc
     29      86    1331
# ls -1 | wc
     86      86    1223

These mixed results seem to be a bug. Columnized output should not disappear down the pipe.

Comment 2 D. E. Evans 2018-07-03 14:37:15 UTC
Clarification: Columnized output should not disappear down the pipe unless explicitly requested with -C.

Comment 3 Kamil Dudka 2018-07-03 15:45:54 UTC
(In reply to D. E. Evans from comment #0)
> GNU coreutils default to -C interactively, but -1 non-interactively.

This is the documented behavior of GNU coreutils.  See the documentation:

https://www.gnu.org/software/coreutils/manual/html_node/General-output-formatting.html#General-output-formatting

The fact that you get different results with -C depending on whether the output is redirected or not is likely caused by the inability to read terminal width while the output is redirected.  You can export the COLUMNS environment variable to specify the width explicitly in both the cases.

Comment 4 D. E. Evans 2018-07-06 16:14:12 UTC
(In reply to Kamil Dudka from comment #3)
> This is the documented behavior of GNU coreutils.

Uhm, what? So three Linux distributions, including Fedora, and the upstream coreutils are behaving incorrectly? Only RHEL has the correct behavior?

I don't think you were paying attention to the primary point of the post: non-interactive behavior should be like -1, as demonstrated in my examples.

Interactive human readable output should not disappear down a pipe.

Comment 5 D. E. Evans 2018-07-06 19:36:35 UTC
(In reply to D. E. Evans from comment #4)
> So three Linux distributions, including Fedora, and the upstream
> coreutils are behaving incorrectly?

Ugh, egg on my face. One of our admins made an ls alias with -C. Ugh.

Comment 6 Kamil Dudka 2018-07-08 21:09:19 UTC
Glad to see this clarified.  Thanks for the explanation!


Note You need to log in before you can comment on or make changes to this bug.