I've piped a command to less
, and now I want to save the command's output to a file. How do I do that?
In this case, I don't want to use tee
, I want a solution directly from less, so that I don't have to rerun a long-running command if I forgot to use tee
.
This question is similar to this one, the only difference is that I want to save all of the lines, not a subset: Write lines to a file from less
Best Answer
From
less
, type s then type the file name you want to save to, then Enter.From the
man
page, underCOMMANDS
:man
page also states that, depending on your particular installation, thes
command might not be available. In that case, you could go to line 1 with:and pipe the whole content to
cat
with:so either:
or:
i.e. type g or < (g or less-than) | $ (pipe then dollar) then
cat > filename
and Enter.This should work whether input is a pipe or an ordinary file.