95

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?

gentmatt
  • 49,722
  • 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: https://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 Jan 06 '15 at 20:51

7 Answers7

79

tput did the trick for me:

tput rmam

disables line wrapping.

tput smam

enables line wrapping.

michid
  • 899
  • 27
    +1 but any way to add horizontal scrolling too? – Erik Kaplun Oct 21 '15 at 10:33
  • Arrow keys work for me to horizontally go to the next screen. – michid Oct 21 '15 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 Jan 28 '16 at 14:54
  • 4
    nice find! added myself a couple of memorable zsh aliases:

    alias wrapon='tput rmam' & alias wrapoff='tput smam'

    – Chris J Allen Apr 12 '16 at 10:57
  • 7
    talk about obfuscated commands – Andy Oct 19 '17 at 15:42
  • @ChrisJAllen - that's kind of funny because that's exactly where I was headed. I love aliases... another handy one I have is alias editbp="open ~/.bash_profile -a "Visual Studio Code" that pops my ~/.bash_profile open in VS Code. For exactly situations like this! – jrypkahauer Oct 03 '22 at 17:23
16

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.

mtklr
  • 459
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')"
Lri
  • 105,117
2

Use cut

myscript | cut -c -100
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).

Nicholaz
  • 637
  • 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 May 27 '13 at 17:02
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
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.

colin
  • 79