0

ls / outputs two lines.

$ ls / 
bin   cdrom  etc   initrd.img      lib    lost+found  mnt  proc  run   share  sys  usr  vmlinuz
boot  dev    home  initrd.img.old  lib64  media       opt  root  sbin  srv    tmp  var  vmlinuz.old

But why does ls / | wc -l tell 26 lines?

$ ls / | wc -l
26
Tim
  • 101,790
  • I think this has to deal with ncurses library because if I do it in a xterm and readjust the window size then the number of lines that appear is different. – SailorCire May 07 '15 at 03:04

1 Answers1

2

As POSIX define, ls will output one entry per line if output is not a terminal, or one of -C, -m, -x was used.

When output is terminal, the output format is implementation-defined.

OSX ls and FreeBSD ls use -1 as default option when output is not to a terminal

cuonglm
  • 153,898
  • Thanks. What does "output is not a terminal" mean? Is a terminal emulator such as gnome terminal emulator not a terminal? – Tim May 07 '15 at 03:55
  • @Tim: Yes, you can read more about it here. In your example, output of ls is a pipe, not a terminal. – cuonglm May 07 '15 at 03:57