Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
1  
Are you confusing date with time? Try man date. –  Elliott Frisch Mar 14 at 17:51
    
@ElliottFrisch No. I think that I was very clear, I speak about time command. –  user258266 Mar 14 at 17:53
    
Does sudo apt-get install --reinstall time help? –  i08in Mar 14 at 17:53
7  
Or maybe the internal shell time with /usr/bin/time –  Rmano Mar 14 at 17:53
add comment

3 Answers 3

up vote 31 down vote accepted

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, shell builtin, version of time. 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 builtin time, you can create a permanent alias as follow:

alias time='/usr/bin/time'

This will overwrite the shell builtin time because the command:

type time

will give the following output now:

time is aliased to `/usr/bin/time'
share|improve this answer
    
Very good explanation, thanks! I went crazy because of this problem. –  user258266 Mar 14 at 18:06
2  
for the shell built commands: {info time} and {type time}. For the binary commands: {which time} and {man time} –  Michael Martinez Mar 14 at 19:09
add comment

The bash and zsh shells have their internal time command. You have to use

/usr/bin/time -f ...

BTW, I discovered that using (from zsh):

~% which  time
time: shell reserved word
share|improve this answer
1  
Thanks for your quick reply, +1... but I must to accept the other answer as it has some more good explanations. –  user258266 Mar 14 at 18:03
add comment

Since, as the other answers explain, time is a shell builtin, the only option available to you is -p:

terdon@oregano ~ $ help time
time: time [-p] pipeline
    Report time consumed by pipeline's execution.

Execute PIPELINE and print a summary of the real time, user CPU time,
and system CPU time spent executing PIPELINE when it terminates.

Options:
  -p    print the timing summary in the portable Posix format

So, you need to run the time that's in /usr/bin. Here are a few ways to do so:

  • Use the full path

    /usr/bin/time -f %Uuser ls >/dev/null
    
  • Use \ which causes your shell to ignore aliases and builtins

    \time -f %Uuser ls >/dev/null 
    
  • Use the command builtin which does the same as the above

    command time -f %Uuser ls >/dev/null
    
  • Use a different shell, one that has no such builtin. For example sh (which is actually dash on Ubuntu

    sh -c "time -f %Uuser ls >/dev/null"
    
  • Use which, which will search through your $PATH (OK, this one is silly)

    $(which time) -f %Uuser ls >/dev/null
    
share|improve this answer
    
Thanks for your answer, too! –  user258266 Mar 14 at 18:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.