Josh Rabinowitz


prefix - adds hostname, time information, or more to lines from stdin (or read from files)


    % tail -f /var/log/some.log | prefix -host -timestamp 

tails a file, showing each line with a hostname and a timestamp like. So if we were tailing a growing file with lines like:

    OK: System operational
    Warning: Disk bandwidth saturated

we would get real-time output like: 2013-10-13 16:51:26 OK: System operational 2013-10-13 16:55:47 Warning: Disk bandwidth saturated 2013-10-13 16:55:49 Warning: Things are wonky: disks spinning backwards 2013-10-13 16:55:50 Error: Data read wackbards 2013-10-13 16:56:10 OK: Spacetime reversal complete

Note that the hostname ( and the date have been prepended to the lines from the file

The prefix program also supports adding arbitrary text, current time to the microsecond, time elapsed since invocation, time since last line output, adding text at the end instead of the beginning of the line, and more.


A text filter that prepends (or appends) data to lines read from stdin or named files, and echos them to stdout


--text='arbitrary text here'

add any particular string you like. For example

    % ./some_program | prefix -text="TestRun17:" -utime > logfile.txt

The above example would prefix each line output from some_program with the time and the text 'TestRun17:' (without the quotes).


Add a timestamp to each line

    % ls -l | prefix -timestamp 


Add a timestamp, showing fractions of a second to each line


    % ls -l | prefix -utimestamp 


Add the hostname to each line


Don't put a space between the original line read and the data added to each line


Show all added data at end of line, not start of line

For example:

    % echo "abc" | prefix -suffix -text=:Run17:

will output

    abc :Run17:

(note how the added text is now at the end of the line) whereas:

    % echo "abc" | prefix -text=:Run17:

would output

    :Run17: abc


Add the time since the prefix program was started to each line


Add time elapsed since last line seen. Shows fractional time.

This can be useful when tailing logfiles or output of programs and you want to see which lines take longer or shorter to output.


Show --elapsedstamp and --diffstamp times in seconds, and never in other units (like minutes or microseconds, for example)


Show each original line read in single quotes


Josh Rabinowitz <joshr>