I am running a server and the log of this server gets logged in terminal, not in any file.
I would like to use less to view this log.
node server.js | less
When I just want to see the log, I use press Shift+F to got to end of file and keep watching logs. When I want to stop it, I use CTRL+C.
Unfortunately, this stops the server as well. I just want to stop watching the end of log without stopping the server.
How to do this?
Best Answer
I can't find any way of exiting the
F
mode inless
, so you will have to use a workaround. For example, save the output to a tmp file and then watch that tmpfile instead:The
&
makes thenode.js
command run in the background. This means thatless tmpfile
will start immediately and will be tracking the tmpfile.Once in
less
, you can press F to enter follow mode but now Ctrl+C won't kill the server, it will only stop the follow. You can now scroll around as you would like and can hit F to resume following.