Why does ls give different output when piped

ls can actually determine if it's outputting to a terminal or a file (with the isatty library call). If it detects a console, it will try to make it more compact for easier viewing.


ls automatically behaves like ls -1 when piped.

This is usually what you want when you are piping ls to awk or something like that, since it will treat the output of ls on a line-by-line basis.

To override this default behavior, you can use ls -C | cat.