LinuxCommandLibrary

ts.1s

Add timestamp to input lines

SYNOPSIS

command | ts [options]
ts [options] < file

PARAMETERS

-a, --absolute
    Output absolute timestamps, typically in a format similar to date(1)'s default output (e.g., 'Mon Jan 1 00:00:00 2023'). By default, ts outputs time elapsed since its invocation, not wall-clock time.

-i, --iso8601
    Output absolute timestamps in the ISO 8601 format (e.g., '2023-01-01T00:00:00.000000+0000'). This is often preferred for machine parsing and consistency.

-r, --relative
    Output relative timestamps, showing the time elapsed since the previous line was processed. This helps in understanding the duration between individual events.

-s, --squash
    Squash consecutive blank lines into a single blank line. Useful for cleaning up output from verbose commands.

-m, --milliseconds
    Include milliseconds in the timestamps. This provides finer granularity for timing events. This is the default for relative timestamps.

-u, --utc
    When using absolute timestamps (with -a or -i), use Coordinated Universal Time (UTC) instead of local time.

-h, --help
    Display a brief help message and exit.

-v, --version
    Display version information and exit.

DESCRIPTION

ts, part of the moreutils package, is a simple yet powerful command-line utility designed to prepend timestamps to each line read from standard input. It is particularly useful for monitoring long-running processes, debugging scripts, or creating log files where precise timing of events is crucial.

By default, ts adds a timestamp representing the elapsed time since the ts command itself started. This allows users to easily see how much time has passed between events in a stream of output. It can also be configured to output absolute wall-clock times in various formats, including ISO 8601, or to show relative time differences between consecutive lines.

The command functions as a filter: it reads input line by line, adds the chosen timestamp, and then prints the modified line to standard output. This makes it highly composable with other Unix commands via pipes, enabling flexible logging and analysis workflows.

CAVEATS

The command ts is part of the moreutils package. It should not be confused with other commands that might share the name 'ts' on some systems, such as task spooler. The exact behavior and available options might vary slightly depending on the specific version of moreutils installed.

While highly effective for general logging, ts introduces a slight processing overhead, which might be a consideration for extremely high-throughput data streams.

HISTORY

ts is a utility included in the moreutils package, a collection of supplemental Unix tools that aim to fill gaps between standard core utilities and common user needs. It was authored by Joey Hess and is designed to be simple, efficient, and composable within the Unix philosophy of small, specialized tools that do one thing well. Its development focuses on providing commonly needed functionality in a lightweight manner.

SEE ALSO

date(1), logger(1), tail(1), less(1), logrotate(8)

Copied to clipboard