3

Is it possible to save the output of earlier tailed logs to a file?

Steps to Reproduce this issue:

  1. tail -f application.log
  2. Ctrl+C to end the logs
  3. Save that output to a file now.

I am assuming an algorithm like this exists.

tail -f application.log | cat >> EOF > /tmp/greppedTMP
1
  • You've used tail -f, which continues until interrupted. Should we assume that you're "looking for something", and it's only when you spot it that you then want the last N rows of the file? If so, can you quantify the "something" and the N? Aug 6, 2023 at 16:49

1 Answer 1

3

How about

tail -f application.log | tee -a /tmp/log

tee will save the STDIN to a file and also send it to STDOUT. (without -a it will overwrite any existing file).

2
  • 1
    Thank you. I finally understood the importance of tee command.
    – achhainsan
    Aug 3, 2023 at 11:01
  • tee can be very useful. One way I often use it is to write to the kernel message buffer with echo hello | sudo tee -a /dev/kmsg
    – Popup
    Aug 3, 2023 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .