15

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.

2
  • 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. Commented Jan 6, 2017 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. Commented Jan 6, 2017 at 8:30

4 Answers 4

38

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 Ctrl+x¹.  To re-enter forward forever mode, press Shift+f (i.e., capital ‘F’).


¹ Ctrl+c (or whatever sends SIGINT) also works but when less is used in a pipeline, that also has the side effect of killing all other commands in the pipeline, so Ctrl+x was introduced in later versions of less to avoid that.

3
  • 1
    Great tip, though it's actually Shift+F to resume (at least on my machine) Commented Oct 19, 2018 at 11:18
  • 4
    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. Commented Apr 20, 2021 at 0:50
  • I need to press Shift+F to follow Commented Apr 3, 2023 at 20:03
1

Well you can use

tail -f <file> | less 

then you can have the best of both worlds!

1
  • 2
    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. Commented Jul 4, 2013 at 12:05
1

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.

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

You can also use

 watch -n 10 cat <file> 

watch(1):

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 screenful).  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.

2
  • 1
    That doesn't provide any method of pagination or scrolling though. Commented Jul 4, 2013 at 12:08
  • agreed but this does the job of scrolling automatically and conveniently. Commented Jul 4, 2013 at 16:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.