8

This question already has an answer here:

I'm usually inside GNU Screen or tmux, and that doesn't give me great scrolling functionality. Is there an alternative to tail -f that allows me to quickly scroll up?

A tool that is like most is to less and more.

This question is related but far from specific. I'm really looking for something that lets me scroll.

marked as duplicate by slm, terdon, jasonwryan, Hauke Laging, Gilles Jul 3 '13 at 22:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • the thing that makes this mildly "not a duplicate" is that you're using tmux and in tmux you can press ctrl+b, [ to enter scroll mode. i'm sure you're aware. but many others may not be: depending on your term, you can then use pgup+pgdn and arrow keys to navigate the backlog, or scroll with your mouse; to exit scroll mode you press q // you can continue using tail -f, or less +F, or cat or scroll an entire bash session for that matter.. it's rare to "need to" invoke less just to scroll through a wall of text. – Shaun Wilson Jan 6 '17 at 8:23
  • if you find tmux hotkeys are "not that great" you may find how-can-i-page-up-or-down-in-tmux-with-terminal-app useful for customizing (or correcting) your configuration -- i've had bad (default) term configs that rendered extended keys useless. – Shaun Wilson Jan 6 '17 at 8:30
21

You can use less +F to start less in its "forward forever" mode. In this mode, less will behave like tail -f, ignoring the ends of files and providing a steady stream of text.

When you want to scroll, press Ctrlc. To re-enter forward forever mode, press F.

  • Great tip, though it's actually Shift+F to resume (at least on my machine) – Bart van Heukelom Oct 19 '18 at 11:18
1

Well you can use

tail -f <file> | less

then you can have the best of both worlds!

  • That will only work for a little while until the user wants to scroll. Then he will have to stop less from reading from the pipe and restart the programs once he is done scrolling. – user26112 Jul 4 '13 at 12:05
0

You can also use

    watch -n 10 cat <file>

man watch:

    watch - execute a program periodically, showing output fullscreen

   SYNOPSIS
   watch  [-dhvt]  [-n  <seconds>]  [--differences[=cumulative]] [--help] [--interval=<seconds>] [--no-title]
   [--version] <command>

   DESCRIPTION
   watch runs command repeatedly, displaying its output (the first screenfull).  This allows you to watch the
   program  output change over time.  By default, the program is run every 2 seconds; use -n or --interval to
   specify a different interval.

   The -d or --differences flag will highlight the differences between successive updates.  The  --cumulative
   option  makes highlighting "sticky", presenting a running display of all positions that have ever changed.

   The -t or --no-title option turns off the header showing the interval, command, and current  time  at  the
   top of the display, as well as the following blank line.
  • That doesn't provide any method of pagination or scrolling though. – user26112 Jul 4 '13 at 12:08
  • agreed but this does the job of scrolling automatically and conveniently. – Raza Jul 4 '13 at 16:42
0

I almost always use less for this sort of thing. I've never used the "forward forever" mode, instead I've got by just using less's runtime shortcuts for scrolling:-

< - Scroll to beginning of stream

> - Scroll to end of stream

Note, that if the buffer is read from a file, and that file has had new content appended to it since less was first opened, then the new content will be visible, the next time > is pressed, even when not in "forward forever" mode.

  • You can also use G to scroll to the end and g to scroll to the beginning, which is useful for vim-users. – evilsoup Jul 3 '13 at 20:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.