ls questions

Asked by COKEDUDE on 2010-12-21

Why does the "-l" option in ls -laC not work? It doesn't display the date, the permissions, owner, size, or time.

~ $ ls -laC
.
..
.adobe
b43-fwcutter_013-2_i386.deb
.bash_history
.bash_logout
bcmwl-kernel-source_5.60.48.36+bdcom-0ubuntu5_i386.deb

Why does the "-C" option in ls -C not work? It does the same thing with and without the "-C" option.

~ $ ls -C
b43-fwcutter_013-2_i386.deb Live_CD
bcmwl-kernel-source_5.60.48.36+bdcom-0ubuntu5_i386.deb mount
broadcom-wl-4.150.10.5 Music
broadcom-wl-4.150.10.5.tar.bz2 Pictures
Desktop Public
Documents Templates
Downloads Videos
fakeroot_1.14.4-1ubuntu1_i386.deb wireless
firmware-b43-installer_4.150.10.5-4_all.deb wl_apsta-3.130.20.0.o
launchpad-integration_0.1.38-1mint1_all.deb

 ~ $ ls
b43-fwcutter_013-2_i386.deb Live_CD
bcmwl-kernel-source_5.60.48.36+bdcom-0ubuntu5_i386.deb mount
broadcom-wl-4.150.10.5 Music
broadcom-wl-4.150.10.5.tar.bz2 Pictures
Desktop Public
Documents Templates
Downloads Videos
fakeroot_1.14.4-1ubuntu1_i386.deb wireless
firmware-b43-installer_4.150.10.5-4_all.deb wl_apsta-3.130.20.0.o
launchpad-integration_0.1.38-1mint1_all.deb

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu coreutils Edit question
Assignee:
No assignee Edit question
Last query:
2010-12-21
Last reply:
2010-12-21
Theodotos Andreou (theodotos) said : #1

Apparently the -l option is incompatible with the -C option. Try omitting the -C option and see the results

There are several things at play here. ls(1) chooses whether to list
files in columns or not depending on whether its standard output
(stdout) is a terminal or not. The theory is that a human prefers
columns whilst other programs and further processing prefer one file per
line.

Even when it wants to output columns if the filenames are very long and
the terminal's width isn't much longer then you will get columns, but
only one of them; there isn't room for two or more.

Let's make a new directory with a few files with shorter names than you
have.

    $ mkdir foo && cd foo && touch a b0123546 ccc dodo
    $ ls
    a b0123546 ccc dodo

ls here has output in columns becaus stdout is a terminal. If I change
that,

    $ ls | cat
    a
    b0123546
    ccc
    dodo

then it switches to one per line. I can force one behaviour or another
instead of it testing stdout for being a terminal. Either one per line,

    $ ls -1 # A digit one, for "one column".
    a
    b0123546
    ccc
    dodo

or columns even when sending stdout down a pipe.

    $ ls -C | cat
    a b0123546 ccc dodo

As for -l and -C, only one can work. The -l (ell for "long") listing
format must place one file per line so it's mutually exclusive with -C.
Which ever is given last wins.

    $ ls -lC
    a b0123546 ccc dodo
    $ ls -Cl
    total 0
    -rw-r--r-- 1 ralph ralph 0 2010-12-21 10:17 a
    -rw-r--r-- 1 ralph ralph 0 2010-12-21 10:17 b0123546
    -rw-r--r-- 1 ralph ralph 0 2010-12-21 10:17 ccc
    -rw-r--r-- 1 ralph ralph 0 2010-12-21 10:17 dodo
    $

Hope that clarifies.

Can you help with this problem?

Provide an answer of your own, or ask COKEDUDE for more information if necessary.

To post a message you must log in.