13

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.

the
  • 900
  • 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 06 '17 at 08: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 06 '17 at 08:30

4 Answers4

33

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.

  • 1
    Great tip, though it's actually Shift+F to resume (at least on my machine) – Bart van Heukelom Oct 19 '18 at 11:18
  • 2
    A related option I find useful is --follow-name. So less --follow-name +F. This will cause less to periodically reopen the file as it follows. This extra option is not needed if the file you are following is being updated normally, but if instead of being updated normally, the file is instead being overwritten with a new file of the same name, then --follow-name will make it work as expected. – Cory Gross Apr 20 '21 at 00:50
  • I need to press Shift+F to follow – commonpike Apr 03 '23 at 20:03
2

Well you can use

tail -f <file> | less

then you can have the best of both worlds!

polarise
  • 1,051
  • 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. –  Jul 04 '13 at 12:05
1

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.
Raza
  • 4,109
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.

Alex Leach
  • 7,910
  • 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 03 '13 at 20:59