Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 need to view large logs files using a bash shell. I was using less to open the files, but since the lines are too lengthy there is some kind of line/word wrapping going on.

Since the files are Log4J logs, and there is a pattern in the beginning of each line, having lines wrapped makes it difficult to analyze the output, so I started using less -S which chops long lines.

But now I need to use tail -f, and it also line wraps the output. Is it possible to disable line wrap in a bash shell for all the commands?

Note: there is an answer to a different question that mentions the escape sequence echo -ne '\e[?7l', but it seems to not work on bash.

share|improve this question
Note that this is unrelated to your choice of shell (bash), but it can depend on your choice of terminal (xterm, Terminal, gnome-terminal, konsole, …). See What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? – Gilles Sep 11 '11 at 18:16
As Gilles mentioned, it is a matter of the terminal emulator. For example, in screen, there is a "wrap" command. In xterm, there is a -aw option to prevent automatic line wraps. Likely there are some X resources for other terminal emulators. What emulator are you using? – Arcege Sep 12 '11 at 20:04
I am using gnome-terminal. – nunaxe Sep 17 '11 at 8:53
@Arcege: Actually, it is +aw for xterm :) But, this solves the issue for output (e.g., on ls -l with a bunch on long Windows-ish names from TPB, it works fine), for input, when entering a command, you probably still want wrap (or, at least you don't want it the way it is now on +aw: try write beyond the "column border" and then backtrack for a huge GFX bug). – Emanuel Berg Nov 9 '12 at 23:37
By the way, it seems neither urxvt nor rxvt can disable line wraps. – Emanuel Berg Nov 9 '12 at 23:50
up vote 3 down vote accepted

Do you actually need tail -f or would something like less +F do? Since it sounds like you still want an interactive pager, it seems to me it would be much easier to stick with less than to reimplement one yourself.

A final note: have you considered tail -f file | less?

share|improve this answer
I made some experiences with screen and xterm as those emulators have options to prevent line wraps. But there is a big difference between truncating the line and hiding the tail of the line so we can view it if we want. Using tail -f file | less -S is not perfect as it seems to disable the -f but it is the best solution I found. – nunaxe Sep 17 '11 at 8:56


less -S +F filename

  • Press Ctrlc to stop tailing and now You can move left and right using cursor keys.
  • Press Shiftf to resume tailing
  • Press Ctrlc, q to quit
share|improve this answer

Supposing you have the COLUMNS variable defined, you can execute

tail -f your-app.log | cut -c -$COLUMNS

otherwise substitute $COLUMNS with the columns width of the terminal, as obtained by stty -a.

share|improve this answer
Another alternative to $COLUMNS (is not immediately updated on SIGWINCH, only on the next prompt) and stty -a (harder to use in script) is tput cols. – manatwork Sep 11 '11 at 12:43
Thanks enzotib. That works, but it trims the line and we are unable to see the end of the long lines. Is is possible to make cut behave like less -S where the long line are buffered and we are able to see the complete line using the directional keys? – nunaxe Sep 11 '11 at 15:12
Uhm, not that simple. I'm thinking of wired solutions as e.g. two separate screen windows each with a tail -f | cut or a script emulating in some way the less behavior. But do not have a solution, at the moment. – enzotib Sep 11 '11 at 16:16
Side-note: cut only counts bytes; unlike less -S, it's going to screw up on coloured text, or anything with ANSI escapes. Might screw up Unicode too. – ELLIOTTCABLE Jun 8 '13 at 20:39
Yes, less -S is more useful with colored text. You can use less -S -E to exit immediately - useful for cutting colored output at $COLUMNS. – blueyed May 13 '15 at 16:42

The terminator (http://software.jessies.org/terminator/) terminal emulator allow to not wrap long lines and has horizontal scrolling (but is written in Java).

share|improve this answer
How do I enable it? It doesn't seem to work by default. – Artem Ice Aug 29 '12 at 13:26
As of this writing, horizontal scroll is on by default. Great, cross-platform recommendation. Thanks! – user7089 Jan 26 '13 at 0:18

Two good answers/examples here


tail -f logfile.log | cut -b 1-80

tail -f logfile.log | cut -b -$(tput cols)

One caveat: at least on the built in terminal on my Mac cut does not seem to handle tab characters very well. It seems it displays them with e.g., 8 spaces but just calculates them as 4 space wide or something like that. In other words, if your terminal is 80 characters wide and your output contains several tabs per line you must set the width to maybe 60 or something like that. YMMV.

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.