← 返回命令列表

Linux command

ts 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Add timestamps

[command] | ts

Use ISO 8601 format

[command] | ts -i

Include milliseconds

[command] | ts -m

Use UTC time

[command] | ts -u

Show incremental time

[command] | ts -s

Show time elapsed

[command] | ts -i

Custom timestamp format

[command] | ts '[%Y-%m-%d %H:%M:%S]'

Convert existing timestamps

[command] | ts -r

说明

ts reads lines from standard input, prepends a timestamp to each line, and writes to standard output. It is part of the moreutils package and is useful for logging, debugging, and monitoring command output over time. The default timestamp format is "%b %d %H:%M:%S" (e.g., "Jan 22 14:30:45"). Custom formats use strftime conversion specifications. Extended specifiers %.S, %.s, and %.T provide subsecond resolution. The -s option shows cumulative time since ts started, useful for measuring total elapsed time. The -i option shows time between lines, helpful for identifying slow operations in pipelines. The -r option converts existing timestamps in the input to human-readable relative times, supporting many common timestamp formats.

参数

-i
Show incremental time elapsed since last timestamp
-s
Show time elapsed since program start
-m
Include milliseconds in timestamps
-u
Use UTC time instead of local time
-r
Convert existing timestamps to relative times (e.g., "15m5s ago")

FAQ

What is the ts command used for?

ts reads lines from standard input, prepends a timestamp to each line, and writes to standard output. It is part of the moreutils package and is useful for logging, debugging, and monitoring command output over time. The default timestamp format is "%b %d %H:%M:%S" (e.g., "Jan 22 14:30:45"). Custom formats use strftime conversion specifications. Extended specifiers %.S, %.s, and %.T provide subsecond resolution. The -s option shows cumulative time since ts started, useful for measuring total elapsed time. The -i option shows time between lines, helpful for identifying slow operations in pipelines. The -r option converts existing timestamps in the input to human-readable relative times, supporting many common timestamp formats.

How do I run a basic ts example?

Run `[command] | ts` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i do in ts?

Show incremental time elapsed since last timestamp