How to read backward from the end of file in less or more?

Solution 1:

I'm sure someone else has a better answer, but

With "less" after you've opened the file:

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.

Solution 2:

For variety, if you actually want/need to read a file backwards (last line first):

tac filename | less

Solution 3:

use:

less +F /path/to/your/file

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.


Solution 4:

w goes up by page. ? does reverse search. h brings up online help.


Solution 5:

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?

Tags:

Unix

Solaris

Less