Take the 2-minute tour ×
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.

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
2  
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
2  
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

4 Answers 4

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

Try:

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

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

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
1  
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

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.