Ubuntu – Why doesn’t the `time` command work with any option

bashcommand linetime-command

I tried to use time command with -f option to format the output of time, but I get the following error:

-f: command not found

Then I tried to use other options -a, -o, etc and I get the same error. Not even time --version doesn't work (--version: command not found).

Don't tell me to read the man because I already do it by many times… All these options are specified there. So, where could be the problem?

Best Answer

Well, even if you don't like it, I will put you to read again with more attention man time. At the end of EXAMPLES section you will find:

  Users of the bash shell need to use an explicit path in order to run
  the external time command and not the shell builtin variant.  On system
  where time is installed in /usr/bin, the first example would become
       /usr/bin/time wc /etc/hosts

So, I'm assuming that you use bash shell which uses an internal version of time, provided as a shell keyword. You can check this using the following command:

type time

and the output will probably be:

time is a shell keyword

If this is the case, then is clear, to use the real time command, you must to use its explicit path: /usr/bin/time.

Further, if you don't want to use anymore the shell keyword time, you can create a permanent alias as follow:

alias time='/usr/bin/time'

This will overwrite the shell keyword time because the command:

type time

will give the following output now:

time is aliased to `/usr/bin/time'