1753884 Members
7347 Online
108809 Solutions
New Discussion юеВ

ls and pipe

 
SOLVED
Go to solution
mobidyc
Trusted Contributor

ls and pipe

Hello,

I have a stupid question and it troubles me.

Why the stdout format of 'ls' is changed through a piped command?

if i do an 'ls' for example, i view all files in a column view.
'ls |more' view a file by line.

so questions are:
- why ?
- is there a way for bypass it ? (without rewrite the output)

Regards,
Cedrick Gaillard
Best regards, Cedrick Gaillard
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: ls and pipe

>Why the stdout format of 'ls' is changed through a piped command?

Probably they make the -1 option the default so that when you feed the piped out to a filter, you get one at a time.
mobidyc
Trusted Contributor

Re: ls and pipe

Hello,

i've just re-read the manpage and i've found the '-C' flag.

this flag allow the multicolum view through a pipe ;)

Regards,
Cedrick Gaillard
Best regards, Cedrick Gaillard
Hein van den Heuvel
Honored Contributor
Solution

Re: ls and pipe

RTFM (Read The Fine Manpage)

For for multicolumn to a pipe use: ls -C
Also check out: ls -m

Please note how the actual multicolumn format depends on the file name length and terminal width. Try stty cols xxx and repeas an ls.
- how wide is a pipe?
- how would a program behind a pipe have to deal with unpredicatable format?

Cheers,
Hein.
James R. Ferguson
Acclaimed Contributor

Re: ls and pipe

Hi Cedrick:

You can force the preservation of the column view by doing:

# ls -x | more

Regards!

...JRF...
Torsten.
Acclaimed Contributor

Re: ls and pipe

Just to add this:
the flag is used with "ls", because "ls" is filling the pipe and "ls" is responsible for the output format, e.g.
# ls -C | more
or
# ls -x | more
this is up to what you want to get.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Peter Nikitka
Honored Contributor

Re: ls and pipe

Hi,

to summarize the answers above:
it's not the pipe, which modifies the output (look at ls >tmpfile!) but the tty:
Without tty you get unmodified output.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"