Add timestamp on each line of bash output

When analyzing the output of a bash script, it can be useful to prepend timestamp before each line to see how long it’s taking to do a specific action.

For this, you can use the ‘ts‘ command:

# echo -e "this\nis\na\ntest" | ts '[%Y-%m-%d %H:%M:%S]'
[2019-05-13 09:14:28] this
[2019-05-13 09:14:28] is
[2019-05-13 09:14:28] a
[2019-05-13 09:14:28] test

If the command ‘ts‘ is not available, you might need to install the package moreutils.