Re:Sick Linux Commands
by start_something on Saturday December 04, 2010 @01:28PM
(#1969809)
Don't forget the -r switch for tailing Rails logs with colored output.
I use emacs shell for same effect.
Re:Sick Linux Commands
by notyourwork on Saturday December 04, 2010 @10:04AM
(#1969319)
Can I ask why not to just use tail? What benefit does this serve?
Can modern tails stop following and search back up the buffer? That's why I use less +F, personally.
Re:Sick Linux Commands
by halfasleep on Saturday December 04, 2010 @10:53AM
(#1969410)
less 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.
Re:Sick Linux Commands
by justinlilly on Sunday December 05, 2010 @09:24PM
(#1973564)
With 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.
Re:Sick Linux Commands
by joshcorbin on Saturday December 04, 2010 @11:36PM
(#1971047)
Wide 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.
Re:Sick Linux Commands
by bretthoerner on Saturday December 04, 2010 @10:48AM
(#1969397)
My only guess would be that you can search inside less if your terminal emulator doesn't support it.
11) Make ‘less’ behave like ‘tail -f’
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.