"ls" command question?

pwharff

Registered
Ok, here's a real stupid question:

How do I tell the "ls" command to output my data in 2 columns?

This is what I've already learned that will not work:

ls --width=45 (this works but is not reliable since the output size can change)
ls -1 (this outputs in single column format, ls -2 doesn't work (why!))
ls -x (this is ls across and I don't understand what it's useful for)

Someone please help me, I've spent over an hour and a half trying to get this to work! I know this is silly, but I need this to work and am willing to hear of suggestions.
 
What do you want to do this for, inputting to a script of some kind or just asthetics?

If it's the latter, the best advice I can give is 'just get used to it', it's part of the feel of linux hehe. If on the other hand there's some kind of script involved, maybe we cna find another solution.
 
Try this:
Code:
echo * | awk '{c=split($0, s); for( n=1; n<=c; n=n+2) print s[n] " " s[n+1]}'

That should do it, printing a space between each file name.

Brian
 
Btoneill, not the output I get:

Code:
[amras@nimbus ~/Desktop]% echo * | awk '{c=split($0, s); for( n=1; n<=c; n=n+2) print s[n] " " s[n+1]}'
Adobe After
Effects 5.5
Adobe Premiere
6.5 Dominico
Scarlatti K.1-K.50
Earth Wind
and Fire
- September.mp3

Is actually:
"Adobe After Effects 5.5"
"Adobe Premiere 6.5"
"/Dominico Scarlarro K.1-K.50"
"Earth Wind and Fire - September.mp3"

They seem to be broken up rather randomly too, not just by say, a space.
 
Back
Top