6

less has an option -S or --chop-lines which prevents lines from wrapping and shows output as one line (often extended beyond screen).

Is it possible to do this with tail -f?

The tail man page doesn't say anything about it.

1 Answers1

7

Not the easiest, and it won't change the output width if you change the screen width.

tail -f myfile.txt | sed -n -e "s/^\(.\{$COLUMNS\}\).*/\1/p"

EDIT: the new one below is easier to type and don't break lines with a tab (thx for the comments):

tail -f myfile.txt | expand | cut "-c1-$COLUMNS"

Alternatively, do you know you can press F inside less?

"F" key : Scroll forward, and keep trying to read when the end of file is reached. Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the "tail -f" command.)

  • nice! both answers work perfect. I wondered if it was necessary to pipe output into tail. I can see myself using the less option alot more, easier to remember, can show line number and can access gzipped files, thanks! – the_velour_fog Mar 13 '15 at 21:09
  • Or cut "-c1-$COLUMNS". Note that it doesn't work properly if there are tabulations or escape sequences or combining characters, or double-width characters. Another approach is to use tput rmam to tell the terminal to stop wrapping (for those that support it) or use a terminal that doesn't wrap like terminator – Stéphane Chazelas Mar 13 '15 at 21:12
  • 2
    less -S +F file works wonderfully, thanks! – lapo Feb 19 '18 at 15:53