Bash tips

From DarkWiki
Revision as of 09:02, 11 December 2019 by Apowney (talk | contribs) (Prepending lines of text with a timestamp)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Prepending lines of text with a timestamp

To put a date/time against each line (perhaps as part of logging), you can use the ts command.

$ echo -e "foo\nbar\nbaz" | ts '[%Y-%m-%d %H:%M:%S]'
[2011-12-13 22:07:03] foo
[2011-12-13 22:07:03] bar
[2011-12-13 22:07:03] baz

If it is not already present on your system, it can be added using apt:

sudo apt install moreutils