G goes to the bottom of the file
^b goes up one page
? searches backwards.
As you said, you can open the file with +G and then use ? and ^b to scroll up. There are likely clever awk things you can do to achieve the same thing in a script.
that's less but starting from the bottom. Also, with +F, if the file is being written to while you are using less, that additional content gets output. This can be useful for logs.
Use the up arrow key to go backwards line by line or ctl+b to go page by page.
I'm sure someone else has a better answer, but
With "less" after you've opened the file:
As you said, you can open the file with +G and then use ? and ^b to scroll up. There are likely clever awk things you can do to achieve the same thing in a script.
For variety, if you actually want/need to read a file backwards (last line first):
use:
that's less but starting from the bottom. Also, with +F, if the file is being written to while you are using less, that additional content gets output. This can be useful for logs.
Use the up arrow key to go backwards line by line or ctl+b to go page by page.
w
goes up by page.?
does reverse search.h
brings up online help.tail -r | less
I don't know why anyone didn't think of this one. Tail grabs the end of a file really easy. Is -r not a common option?
I'm surprised nobody brought this up before, but:
?pattern
searches for pattern backwards.N
finds the previous match of the pattern (that is, searching backwards).For reference,
/pattern
searches for pattern forward andn
finds the next match of the pattern. That's the way the search is commonly used.While using
more
orjournalctl -xe
using space bar takes you 1 page down. That worked for me. Hope this helps.Another alternative, after you have started less on a file:
alt + "end-key"
With "end-key" I mean the key that is usually located below the "home-key" on a keyboard.
Open the file straight to the end (
+G
) withless +G path/to/filename
.It will automatically start "calculating line numbers." If the file is huge (ex: many GiB), press Ctrl + C to stop that, since it could take forever.
Now, here are some keys to navigate:
/
to search forwards, pressing n to go to the next match down, and Shift + n to go to the next match up.?
to search backwards, pressing n to go to the next match up, and Shift + n to go to the next match down.References
less +G filename
to open the file straight to the end.man less
If you're looking for something specific, this might do it:
I use it for searching log files. It's still in the 'wrong' order though, but much shorter.
After reading Dennis Williamson's answer, that's my new method =)