5

The command tail -f command is great for tracing, and in terminal it's very helpful to be able to, for example, hit enter, and type a comment like

-- after xyz change... --

For record purposes, I would like to be able to pipe the tail output to terminal, plus my annotations, to a second file. Is this possible (other than copying and pasting the output manually)? Thanks!

5

This does what you need:

sh -c 'tail -f file & cat' | tee file2

Note, it duplicates your comments for the terminal output when you press enter.

It works also with {...} and (...) instead of sh -c, but then tail -f won't stop running when you press ctrl+c.

  • The fact that it duplicates my output on the terminal is not a blocker, after all I'm using those lines to separate – Oliver Williams Jul 3 at 18:08
  • What shell is your sh -c ? a shell that kills its background jobs on exit/interrupt seems non-standard – LL3 Jul 5 at 23:15
  • It is dash .... – pLumo Jul 6 at 4:30
  • How does your Dash kill the tail on ctrl-c ? dash on my ubuntu (14 and 19) doesn't do it, which is what I'd expect because that sh -c command has no job control enabled, thus background processes are started immune to SIGINT (POSIX defined behavior for shells), and AFAIK dash doesn't kill its children automatically on exit either – LL3 Jul 6 at 14:56
-1

Use Tee

tail -f /var/log/messages | tee test.txt
  • 3
    this doesn't add the comments to the file – pLumo Jul 3 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.