15

I am trying to get the time it takes to run a command, with the output in a specific format:

time -f "%E" ls -l

This is similar to the example in the man page (and on the online man page). However when I run this command I get:

-f: command not found

It appears as though the time command is not reading the -f as an argument, rather as the command I am trying to run.

How can I get the execution time for a command in a specific format?

muru
  • 193,181
  • 53
  • 473
  • 722
Isaac
  • 253
  • 2
  • 7

3 Answers3

21

This is because time is a bash builtin command - and the builtin doesn't support the options you're trying to use.

Try this, use the full path of time to skip the built-in and use the real one:

/usr/bin/time -f "%E" ls -l
Caesium
  • 15,517
  • 4
  • 40
  • 48
3

Unfortunately, time is both a bash keyword and a program in /usr/bin. If you specify the full path to time like:

/usr/bin/time -f "%E" ls -l

You will get the output you were expecting.

galoget
  • 2,943
  • 2
  • 20
  • 24
Mike Pelley
  • 603
  • 5
  • 12
0

to change format of bash builtin time use TIMEFORMAT variable

TIMEFORMAT
      The  value  of  this parameter is used as a format string specifying how the timing information for pipelines prefixed with the time reserved word should be displayed.  The % character introduces an escape sequence that is expanded to a time value or
      other information.  The escape sequences and their meanings are as follows; the braces denote optional portions.
      %%        A literal %.
      %[p][l]R  The elapsed time in seconds.
      %[p][l]U  The number of CPU seconds spent in user mode.
      %[p][l]S  The number of CPU seconds spent in system mode.
      %P        The CPU percentage, computed as (%U + %S) / %R.

      The optional p is a digit specifying the precision, the number of fractional digits after a decimal point.  A value of 0 causes no decimal point or fraction to be output.  At most three places after the decimal point may be  specified;  values  of  p
      greater than 3 are changed to 3.  If p is not specified, the value 3 is used.

      The optional l specifies a longer format, including minutes, of the form MMmSS.FFs.  The value of p determines whether or not the fraction is included.

      If this variable is not set, bash acts as if it had the value $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'.  If the value is null, no timing information is displayed.  A trailing newline is added when the format string is displayed.
Sloth
  • 1
  • 1