2

I'd like to know the time when line was appended when file is being tail -f'ed.

Is it possible to configure tail to do something like that?

1 Answer 1

1

It is possible. Try the following:

tail -f /tmp/log.txt | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }'
3
  • If you're dealing with log files that you are creating, it may be better practice to have the logging program add timestamps to the log instead of the above
    – earthmeLon
    Nov 4, 2011 at 15:21
  • Also this will only tell one the time tail outputted the line. To see this try tail --sleep-interval=300 somefile
    – waltinator
    Jan 22, 2015 at 15:42
  • Oops tail only pays attention to --sleep-interval when it is not using inotify. So my example above should be tail ---disable-inotify --sleep-interval=3000 -f somefile
    – waltinator
    Jan 22, 2015 at 15:55

You must log in to answer this question.

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