Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm sure it's very simple, but I can't remember how to tell a terminal pager (more/less/pg/most) to display a long list in columns.

Since my input is just a list of short elements, displaying it the same way ls does it by default would save me needless scrolling and precious screen real estate.

bad:

aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii

good:

aaa ddd ggg
bbb eee hhh
ccc fff iii
share|improve this question

3 Answers 3

Use column.

Example:

ls -1 | column -c 100

This will format the output of ls -1 (one entry per line) to fit as many columns of equal size as possible in rows that are 100 character wide.

share|improve this answer

You can use paste to join lines from stdin:

paste - - - < filename
share|improve this answer

Similar to Daniel Beck's answer:

$ echo {a..c}{a..c}{a..c}| tr \  \\n | column | sed 's/\t/ /g' | $PAGER
aaa aba aca baa bba bca caa cba cca
aab abb acb bab bbb bcb cab cbb ccb
aac abc acc bac bbc bcc cac cbc ccc

The key is to make the output more compact by substituting tabs with spaces.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.