47

I found out it's possible to show the output of the ls command vertically using the -1 switch:

$ ls -1

But couldn't find it in the manual of ls. Is it a secret option?

B Faley
  • 4,343
  • 11
  • 39
  • 48
  • 1
    man ls does tell: -1 list one file per line. Info pages usually contain more information, try info ls. – devnull Feb 01 '14 at 09:11

3 Answers3

58

The manual is out of date with the program. Try ls --help | grep -- ' -1':

  -1                         list one file per line

It is one of the last options described if you just do ls --help.

Timo
  • 6,332
  • /bin/ls also gives output in columns, at least it does on my system. What is your ls aliased to? – terdon Feb 01 '14 at 19:17
  • Recent addition? OK, it's not in V7. But 2BSD had it. The oldest GNU version I can find right now, fileutils 3.12 had it, including documentation in the man page, and the ChangeLog goes back to version 1.0 in 1990 with no mention of it being added as a new option. I think it's always been there. –  Feb 01 '14 at 20:22
  • @timo, Thanks for the answer. Nice way to Explanation. Works for me. – AMIC MING Apr 10 '19 at 15:13
  • Gotta love those ambiguous characters! – Jim Fell Apr 19 '23 at 21:20
6

As @Timo indicates -1 is in the help, and @terdon points out the -1 is documented in the manual for some version. coreutils 8.13 has that error in the man page, version 8.22 doesn't anymore.

In the hacking guidelines for coreutils. It is specified that

The man pages are generated from --help output, so you shouldn't need to change anything under man/.

So there must be something broken in the conversion causing the similar -m to show up but not the -1. While building ls with the patch I proposed in answer to @timo's question, the manual page for ls gets regenerated correctly and the relevant part reads:

  -Z, --context
          print any security context of each file

-1 list one file per line

-0 list files separated with NUL

--help display this help and exit

--version output version information and exit

And without that patch, the -1 shows up in the manual as well. The git log shows no specific action to correct this. As recent as Sep 2013 help2man, which is used to generate the man pages, was updated. The help2man ChangeLog doesn't show a specific action either.

Anthon
  • 79,293
3

I suppose this will depend on your ls implementation but on my LMDE (basically Debian testing) I have:

$ man ls | grep -- '-1'
              across -x, commas -m, horizontal -x, long -l, single-column  -1,
       -1     list one file per line

As well as (yes, it's the same output)

$ ls --help | grep -- '-1'
              across -x, commas -m, horizontal -x, long -l, single-column  -1,
       -1     list one file per line
terdon
  • 242,166