Linux command-line snippet for absolute timestamps with subsecond resolution in ISO 8601 format

Use

date +%FT%T_%N_ns

Sample output:

2024-02-05T22:27:08_064175582_ns

That is sortable output, but a resolution of 1/100 second is probably sufficient. The output can be rounded by postprocessing.

A sample application

For example, it can be used to get absolute timestamps for start and end of a command (not just the run time in seconds):

clear; echo ; echo "Start time: $(date +%FT%T_%N_ns)"  ; echo
git log -i -S"Q10 Max" --all  --  keyboards
echo ; echo "End time:   $(date +%FT%T_%N_ns)"  ; echo

The absolute time may be important later. For example, to know/document when a particular command was run (and how long it took).

Leave a Reply

Your email address will not be published. Required fields are marked *

*