97

I often read outputs in the terminal that get wrapped as they are too long. Since there is no way that I can modify the printed output, I need to let the Terminal allow for horizontal scrolling.

Is there a modification I can make to the default OS X Terminal to disable line wrapping and allow for horizontal scrolling?

Or do you know another alternative I can use?

1
  • Old question, but seems to me that it is still unresolved. I am in need for the same answer, since for me i cannot further edit the output of for example GCC: gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html With the flag -fmessage-length=0 set, i still get multi-line warning/error output. and I don't (for now).
    – Michahell
    Commented Jan 6, 2015 at 20:51

7 Answers 7

80

tput did the trick for me:

tput rmam

disables line wrapping.

tput smam

enables line wrapping.

6
  • 27
    +1 but any way to add horizontal scrolling too? Commented Oct 21, 2015 at 10:33
  • Arrow keys work for me to horizontally go to the next screen.
    – michid
    Commented Oct 21, 2015 at 14:06
  • 11
    I don't see how to use the arrow keys... they don't work for me. This solution seems to just truncate the lines to the width of the current window. When I make the window bigger there is just empty space to the right of lines that I know contain more characters. Still, this solution is useful for my purposes since I'm displaying logs and the information on the far right is inconsequential at the moment.
    – Jason
    Commented Jan 28, 2016 at 14:54
  • 4
    nice find! added myself a couple of memorable zsh aliases: alias wrapon='tput rmam' & alias wrapoff='tput smam' Commented Apr 12, 2016 at 10:57
  • 7
    talk about obfuscated commands
    – Andy
    Commented Oct 19, 2017 at 15:42
17

Pipe the output through less -S:

   -S or --chop-long-lines
          Causes lines longer than the screen width to be chopped (truncated)
          rather than wrapped.  That is, the portion of a long line that does
          not fit in the screen width is not shown.  The default is  to  wrap
          long lines; that is, display the remainder on the next line.

I tried to explain what might be going on here, though this won't result in a way to scroll horizontally with a scrollbar, as you seem to want.

1
  • How to make less display normally instead of in a separate qable screen?
    – Pacerier
    Commented Apr 25, 2020 at 15:04
6

iTerm 2 doesn't seem to support disabling line wrap either. You might just use less or cut though:

less /var/log/system.log
expand /var/log/system.log | cut -c 1-$COLUMNS
less -s <<< "$(osascript -e 'tell app "Terminal" to contents of window 1')"
2

If you are (as others suggest as a solution, although I think you asked about direct output) then redirect output to a somename.log file and open it with Applications>Utilities>Log-Viewer (or from commandline as open somename.log).

It's not in the terminal but I found the log viewer to the one best suited to deal with large amount of output (searching, scrolling, filtering).

1
  • I think you mean the Console.app, right? There is no Log Viewer.app in the Utilities. However, the console also wraps, the only difference is that long lines are contracted by default. You have to click them to read everything - so, this won't help unfortunately.
    – gentmatt
    Commented May 27, 2013 at 17:02
2

Use cut

myscript | cut -c -100
1

Depending on what you are trying to stop wrapping you could use vim. So launch vim on the file with the long lines, and then type:

:se nowrap
1
  • 2
    This won't help, since I'm not reading files. I'm reading network information via lsof.
    – gentmatt
    Commented May 27, 2013 at 16:57
0

I suggest using lnav (easily found), it is a fantastic log and stream viewing tool and by default does single lines with horizontal scrolling. All movements by keyboard keys. You can also easily hide lines matching grep patterns so that you can concentrate on the most relevant data. I use it almost ALL the time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .