Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 7 down vote accepted


psql ... | less -S

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

share|improve this answer
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

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

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

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

share|improve this answer

Your Answer


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.