19

I have two commands that I through were the same, but they don't share the same parameter:

  • time -f "%E %C" mycommandtomeasure
  • /usr/bin/time -f "%E %C" mycommandtomeasure

The first one does not execute, while the second one does. The first one cannot find the -f parameter. When checking whereis time I do get the path /usr/bin/time, so I understand it this way that time is the same command as /usr/bin/time.

Apparently, my assumption is wrong though. Could someone help me to elaborate?

1
  • @αғsнιη Thank you for the link. it explains the matter. The reason I took Byte Commanders answer is because he helped me understand the entire reason behind the two time commands and in a general way how to find it out as this may also have happened with any other command.
    – Socrates
    Jul 12, 2018 at 9:55

2 Answers 2

30

Let's have a look at what time actually is using the type command (see help type):

$ type -a time
time is a shell keyword
time is /usr/bin/time

So apparently, time on our system is both

  • a keyword directly built into your Bash shell
  • an executable file /usr/bin/time

Because shell keywords take precedence over executables, what you actually run when typing only time is the shell keyword. You also see that from the order in which type -a lists them, or from the output of just type time, which only lists the one effective type.

Now, let's check what each of those can do:

  • Executables usually have a manpage (manual page), which we can open and read using the man command, i.e. here man time.

  • To get help about stuff built into Bash, you have to use the help command: help time

You will note that the shell keyword supports less options than the executable, but it has other advantages, as you can e.g. time complex Bash constructs like pipelines with it. See the end of this answer for an example.

If you need to use the executable instead of the shell keyword though, you can either type the full path, i.e. /usr/bin/time, or you can prefix the command with a backslash to stop Bash from evaluating it: \time

By the way, while time is a shell keyword in Bash, it does not exist in sh (Dash), where you would only get the executable.

4

When you run time you run a built into shell command that doesn't support all features.

When you run /usr/bin/time, you run a real GNU time program.

You can set an alias to run always the "real" one.

Not the answer you're looking for? Browse other questions tagged .