Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are numerous programmes (e.g. ts in moreutils), and various bash one-liners to prepend the output of a command/pipe with the timestamp of when that line was 'printed'.

However is there a command that, for each line that it gets, will print the time since the command started (and/or when it first saw a line), and the current line? So rather than print the current time, it'll print how long since that command started? (aswell as the line aswell)

When running commands that take a while, and spew a lot of output, it can be helpful to know how long you've been looking at it.

It would be trivial to whip a simple command up, but I don't want to re-invent the wheel.

This is on an Ubuntu Linux system.

share|improve this question
up vote 4 down vote accepted

Here's one way:

SECONDS=0    # it will already be initialized to zero at the start of the script
while read -r line
    echo "$SECONDS: $line"
done < file    # or < <(command)

SECONDS is a variable that automatically increments every second.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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