Search code examples
shellgnuls

GNU 'ls' command not outputing the same over a pipe


When I execute the command ls on my system, I get the following output:

System:~ user# ls
asd  goodfile  testfile  this is a test file

However, when I pipe ls to another program (such as cat or gawk), the following is output:

System:~ user# ls | cat
asd
goodfile
testfile
this is a test file

How do I get ls to read the terminal size and output the same over a pipe as it does when printing directly to the terminal?


This question has been solved.

Since I'm using bash, I used the following to achieve the desired output:

System:~ user# ls -C -w "$(tput cols)" | cat

Solution

  • Since I'm using bash, I used the following to achieve the desired output:

    System:~ user# ls -C -w "$(tput cols)" | cat