Score:1

What program is being executed upon time command?

kr flag

In my terminal in Ubuntu, I want to execute the time program with option -v, but it fails:

$ time -v ls
-v: command not found

However if I specify the path /usr/bin/time of the program as such, it works:

$ /usr/bin/time -v ls
foo  bar  baz
        Command being timed: "ls"
        User time (seconds): 0.00
        ...

So it seems that time and /usr/bin/time are different executables. But to my surprise, when trying to identify time with which, it tells that it is the same:

$ which time
/usr/bin/time

I am puzzled, can someone explain what is happening?
Is the result of which somehow not correct?

Score:3
ws flag

Try running type time - it will probably tell you that on your system time is a shell keyword (compare this with orher comands like echo, ls and nano).

If you explicitly want to run /usr/bin/time, then type /usr/bin/time -v ls

Louis Coulet avatar
kr flag
Yes indeed ```time``` is a shell keyword, I didn't know about those, that's treacherous!
ng flag
It's not a keyword, it's a builtin. There is no such thing as a "keyword" in a POSIX shell. There are the *reserved words* `!`, `{`, `}`, `case`, `do`, `done`, `elif`, `else`, `esac`, `fi`, `for`,`if`, `in`, `then`, `until`, and `while` which are reserved in all shells and `[[`, `]]`, `function`, and `select` which are reserved in some shells. As you will notice, `time` is not one of those.
ph flag
@JörgWMittag In bash, it's a keyword. See the [Reserved Words section of the bash manual](https://www.gnu.org/software/bash/manual/bash.html#Reserved-Words). This allows things like applying `time` to [an entire pipeline](https://www.gnu.org/software/bash/manual/bash.html#Pipelines) (though this is disabled in POSIX mode).
Score:3
ar flag

It's both a binary in /usr/bin/time and a Shell builtin.

$ type time
time is a shell keyword

Shell builtins have precedence over binaries on disk. To use the binary, you have to specify the path, e.g. /usr/bin/time -v ls

The Wikipedia Article has some more information on the topic.

Louis Coulet avatar
kr flag
Yes indeed, thank you for the article.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.