less +F and Friends

less +F and Friends

Robbert Haarman

2013-01-06

Posted by inglorion
at 2014-04-04 00:16:01

Discovery of the day: "less +F". It's something I've been looking for, but hadn't found until recently. Some background: "tail" shows the last couple of lines in a file. "tail -f" does the same, but also "follows" the file, showing new lines as they are added to the file. "less" is a pager, it allows you to view a file screenful by screenful. It also allows you to scroll up, search, and a number of other useful things. One of those is a follow function, which basically does the same as "tail -f", but allows you to go back to less's normal mode of operation, so you can scroll back, etc.

Often, I want to see new lines being added to a file, with the option to scroll back, search, etc. if something interesting happens (e.g. an error message is printed). The way I used to do this is by running "less $filename", then typing an uppercase F, which invokes the follow function. Today, I discovered that you can do this in one go by doing "less +F $filename". This also works for other less commands, e.g. "less +G $filename" will run less on a file, but start at the end of the file, rather than at the beginning. "less +/foo $filename" will open the file and scroll to the first occurrence of "foo".