3 ms·
Here's one more people should know about: 11) Make ‘less’ behave like ‘tail -f’ less +F somelogfile Using +F will put less in follow mode. This works sim
by samstokes 16y ago
Here's one more people should know about:
11) Make ‘less’ behave like ‘tail -f’
less +F somelogfile
Using +F will put less in follow mode. This works similar to ‘tail -f’. To stop scrolling, use the interrupt [i.e. Ctrl-C]. Then you’ll get the normal benefits of less (scroll, etc.).
Pressing SHIFT-F will resume the ‘tailling’ [sic].
This is really useful for watching logs while debugging - if you see something interesting scroll past, Ctrl-C to freeze it, then you can use ? with a regex to search back for previous occurrences of the interesting thing.
To explain the cryptic +F syntax: anything you pass after the + is interpreted by less as if you'd pressed those keys while less was running, and Shift-F enables follow mode. So +F just puts less straight into tail mode.
Conversely, you can enable regular command-line options once a less session is already running, by just typing them. For example, I usually run 'less -i' for case-insensitive search, but if I forget the -i, I can just type -i once less has started to disable case sensitivity.
less is actually much more powerful than its standard use as a mere pager would suggest.
- notyourwork 16y agoCan I ask why not to just use tail? What benefit does this serve?
- jfb 16y agoCan modern tails stop following and search back up the buffer? That's why I use less +F, personally.
- bretthoerner 16y agoMy only guess would be that you can search inside less if your terminal emulator doesn't support it.
- halfasleep 16y agoless allows you to stop and resume easily, without losing any of the output of your command (useful if you are watching the output of a process as well). Also less doesn't clutter the scrollback of your terminal with output from tail.
- joshcorbin 16y agoWide lines like from syslog, frequently you want one event per line and not to have wrapping occur. The -S switch to less is a boon here.
- justinlilly 16y agoWith less, you can do: less myfile.log &ERROR # filter out any line that doesn't match the regexp ERROR F # capital f enters follow mode Now you're tailing a log with a custom grep, which is retroactive on history as well.
- start_something 16y agoDon't forget the -r switch for tailing Rails logs with colored output.
- yters 16y agoI use emacs shell for same effect.