How can I save the current contents of less to a file?
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Romantic Lands Beckon
--
Chapters
00:00 Question
00:32 Accepted answer (Score 138)
00:48 Answer 2 (Score 32)
01:32 Answer 3 (Score 8)
01:58 Answer 4 (Score 0)
02:22 Thank you
--
Full question
https://superuser.com/questions/290908/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #pipe #less
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Romantic Lands Beckon
--
Chapters
00:00 Question
00:32 Accepted answer (Score 138)
00:48 Answer 2 (Score 32)
01:32 Answer 3 (Score 8)
01:58 Answer 4 (Score 0)
02:22 Thank you
--
Full question
https://superuser.com/questions/290908/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #pipe #less
#avk47
ACCEPTED ANSWER
Score 142
On my system, man less
says
s filename
Save the input to a file. This only works if the input is a
pipe, not an ordinary file.
Works for me!
ANSWER 2
Score 36
The accepted answer doesn't work on the Mac -- as @benroth says, pressing s
just moves down a line -- but you can use a different method.
In less --help
:
|Xcommand Pipe file between current pos & mark X to shell command.
and
A mark is any upper-case or lower-case letter.
Certain marks are predefined:
^ means beginning of the file
$ means end of the file
So if you go to the top of the buffer (<
) and then:
|$cat > /tmp/foo.txt
the contents of the buffer will be written out to /tmp/foo.txt
.
ANSWER 3
Score 9
When your less
is opened, you can save the complete output to a file.
Like vim
, less supports commands.
Just type the key s
, then less
will ask you the name of the file where you wish to save the content, just type the file name and then type Enter
.
Cheers
ANSWER 4
Score 0
No if you have started less, but if you know before yu want to send it to less and a file then you can use the tee command
command | tee out_file | less