Linux – How to copy text from less

lesslinuxterminal-emulator

How might one copy the entire buffer being displayed by less?
No need to select specific text, I want it all.
Copying to the clipboard is preferable but if we can output it to a file that works too.

I've tried using generic vim commands like :w and the ones listed here but less doesn't seem to accept commands like that.

EDIT
I must be able to do this from within less. Let's say that less is pipeed to from an alias, I have no control over how less is actually called. I am just presented with the result.
I found a way to save the buffer (see my answer below) so now I just need to see if there is any way to select and copy. There probably isn't, given the restrictions.

Best Answer

Dump less buffer into clipboard using xsel as follows:

  1. Open file $ less file.txt

  2. In less press |(pipe) then $

  3. Write xsel -i and press Enter

less buffer content should be copied.

Related Question