Why does ls give different output when piped

前端 未结 3 1444
青春惊慌失措
青春惊慌失措 2020-12-02 01:41

Printing to terminal directly:

$ ls
a.out  avg.c  avg.h

Piping to cat

$ ls | cat
a.out
avg.c
avg.h
         


        
3条回答
  •  北海茫月
    2020-12-02 02:30

    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.

提交回复
热议问题