Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running

psql -U postgres template1 -c "select * from pg_stat_activity"

and the output is too wide for my terminal. Is there a *nix command I can use to prevent the output from wrapping? Maybe a setting in screen that enables virtual horizontal scrolling?

share|improve this question
add comment

4 Answers

up vote 7 down vote accepted

Try

psql ... | less -S

The -S option to less enables horizontal scrolling instead of line wrapping.

share|improve this answer
1  
Note that you can still scroll horizontally without -S. When scrolled to the first column it will wrap, but once you scroll right the text will be "unwrapped". –  Ignacio Vazquez-Abrams Apr 17 '10 at 3:34
    
Interesting, I never noticed that. –  David Z Apr 18 '10 at 0:05
add comment

If you don't want to (or can't) use a pager for some reason, you can also use cut:

psql ... | cut -c1-60

This takes only the first 60 characters of each line. No scrolling however.

share|improve this answer
add comment

fmt is probably what you want; it will wrap lines at a given column. pr has more options and is more complex.

share|improve this answer
add comment

Consider adding -P format=wrapped to your psql invocation, if you're using pg 8.4 or newer.

share|improve this answer
add comment

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.