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.
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.
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.)
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 usetput 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:12less -S +F file
works wonderfully, thanks! – lapo Feb 19 '18 at 15:53