how to format `time` output

I’m using Ubuntu 23.10 x64. The time program has an -f flag but when I run it says -f command not found.

time -f "%Uu %Ss %er %MkB %C" ./countwords hamlet.txt

I’m trying to get the time program to output the memory use in addition to the default output.

Asked By: Leahcim


You’re probably running bash (or zsh), which has its own time command built-in so that it can time a whole pipeline and not just a single command:

type time
  time is a shell keyword

help time
  time: time [-p] pipeline
      Report time consumed by pipeline's execution.

You can see that the built-in time command has only an optional -p flag.

If you want to use the external time command (/usr/bin/time) as shown in man time you will need to specify it explicitly:

command time -f '%Uu %Ss %er %MkB %C' ./countwords hamlet.txt
Answered By: Chris Davies
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.