Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to output with timestamp using ts

📅 2014-Sep-11 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ log, timestamp, ts ⬩ 📚 Archive

You might sometimes want to create a log of the output from a program. Going into the program and adding a timestamp for each print command might seem cumbersome or not possible. It is here that the tiny ts utility makes itself useful. Pipe any output through it and it prefixes a timestamp to each line. Pipe the output of a long-running program through it and then save it to a file and you have a log!

To get this program, install the moreutils package:

$ sudo apt install moreutils

To use it:

$ ./my-program | ts > log.txt

Tried with: MoreUtils 0.5 and Ubuntu 14.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧