Effectively detaching 'less' from a pipe
smithi at nimnet.asn.au
Tue Feb 27 12:20:02 UTC 2007
In freebsd-questions Digest, Vol 167, Issue 5
At Message: 19
On Mon, 26 Feb 2007 20:27:41 -0700, Kelly Jones <kelly.terry.jones at gmail.com> wrote:
> I often run commands piped to 'less', to make sure the command is
> working OK by looking at the first few lines of output.
> Once I'm convinced, though, I'd like to "get rid" of less, and just
> have the rest of stdout spewed to the terminal (and/or /dev/null
> and/or to a file I specify).
> In other words, I want to stop hitting 'space' until my program terminates.
What Matthew said about using 'F' to follow output tail is very handy.
> How can I do this?
> My current kludges (both ugly):
> 1. do "command > file" and then "tail -f file | less" (this mostly
> works, but takes a while to get started because of buffering issues)
> 2. do "command | less", and once I'm happy w/ the output, hit 'q' to
> quit less (and thus terminate program) and then do "command >
> /dev/null" (works, but wastes time, since I have to run the command
> once just to look at the first few lines and then abort it)
When you've piped something to less that you want to save, or save some
part of, press 'g' to go to top of file (or position the top of what you
want to save at top of screen), press 'm' and some letter (I mostly use
'mm' for speed) to mark that spot, press 'G' to go to bottom of file (or
otherwise position the end of what you want at bottom of screen), then
press '|' then (as prompted for) the letter of your mark (eg here '|m')
Then at the '!' command prompt offered, type 'cat - >somepath/filename'
to capture the file, or snippet. If you use >> instead of > you can cat
interesting sections of your output to a file; using up/down arrow at
'!' you can recall commands used, for each mark/move/pipe/cat sequence.
More information about the freebsd-questions