272

Is there a way to open less and have it scroll to the end of the file? I'm always doing less app.log and then pressing G to go to the bottom.

I'm hoping there's something like less --end or less -exec 'G'.

Miles
  • 6,927

3 Answers3

409

less +G app.log

+ will run an initial command when the file is opened

G jumps to the end

When multiple files are in play, ++ applies commands to every file being viewed. Not just the first one. For example, less ++G app1.log app2.log.

Miles
  • 6,927
  • 9
    Great, this also works for my use case: Go to the first line that says "abc": less +/"abc" – Torsten May 13 '20 at 13:00
  • Works great for my https://ohmyz.sh alias hist="omz_history -E | less -i +G".

    With this you get a command line history with human readable timestamps -E and less being scrolled to the bottom thanks to +G with the youngest entries, and can then scroll up with the arrow keys or search case insensitive right away thanks to -i.

    – porg Jan 26 '21 at 15:29
  • 1
    G is great, but I really think F is better, as the other answer states. Pressing F while less is open is identical to pressing Ctrl + End. It will continually read and load the end of the file. This is very useful for a growing log file. – Gabriel Staples Jan 19 '22 at 18:41
  • @alper as default, less "scrolls" to top – Valerio Bozz Jul 18 '23 at 16:50
84
less +F filename

will go to the end and continually load the latest contents of the file.

From less man page:

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

John E.
  • 841
  • 5
    Note that pressing F while less is open is identical to pressing Ctrl + End. It will continually read and load the end of the file. This is very useful for a growing log file. – Gabriel Staples Jan 19 '22 at 18:34
12

From the less man page:

If a command line option begins with +, the remainder of that option is taken to be an initial command to less. For example, +G tells less to start at the end of the file rather than the beginning, and +/xyz tells it to start at the first occurrence of "xyz" in the file. As a special case, + acts like +g; that is, it starts the display at the specified line number (however, see the caveat under the "g" command above). If the option starts with ++, the initial command applies to every file being viewed, not just the first one. The + command described previously may also be used to set (or change) an initial command for every file.

Dfaure
  • 243