How to fix “time: command not found” error in Linux

Are you looking for a way to fix “bash: time: command not found” error messages in Linux.

The time command is used to measure how long it takes the processor to execute a specific command or script in Linux. It provides a summary of real-time, user CPU time, and system CPU time consumed by running something.

real‘ time is the time it takes a command to run in wall clock time, whereas ‘user‘ and ‘sys‘ time are the amount of CPU seconds that the command consumes in user and kernel mode, respectively.

If you’re encountering “bash: time: command not found”, it simply means the system cannot find the time executable placed in locations in PATH environment variables, such as /usr/bin or /usr/local/bin. We’ve covered some of the most common “command not found” errors in the past, namely “pip: command not found”conda: command not found or “apt-get command not found”.

In this short article, we will show you a few solutions to fix “time: command not found” error in Linux.

Run time command in explicit path

If you’re trying to run time using Bash script, it is likely you’re not actually calling the time executable, but a shell reserved words. Reserved words are words that have special meaning to the shell. They are used to begin and end the shell’s compound commands.

In Bash, time is a reserved keyword, along with done, if, else, elif, while, until, etc. They are recognized as reserved when they’re either unquoted or being the first word of a simple command.

In order to check if this is really the case, run type time in the terminal. The output below indicates that the command time is currently recognized as reserved keywords. In contrast, apt is an executable located in /usr/bin/apt.

In order to properly run time command, you must use its explicit path at /usr/bin/time.

Alternatively, if you don’t want to run time using explicit path every single time, you can overwrite the shell keyword time by specifying an alias. Run the following command to do that.

alias time='/usr/bin/time'
Code language: JavaScript (javascript)

After that, if you run type time in the terminal again, you will see it returns time is aliased to /usr/bin/time' instead of time is a shell keyword .

Use time in bash script

If you’re including time as part of your Bash script, you should be aware that you’re essentially calling a Bash reserved keyword. Now you have a few options to fix this :

  • Replace time with /usr/bin/time (or the exact location to time executable)
  • Prefix time with eval, so that time is taken as argument and Bash evaluates/interprets the code in it.
  • Replace time with (which time), which essentially calling which program to find the location of time command.

Command not found errors are common in Linux; they usually indicate the absence of executables in the system. If you’re also seeing a “command not found” error message, you may want to check out our other guides to fix zsh: command not found, apt-get: command not found and “make: command not found”. Please leave a comment below if you have any suggestions or find an error in the article.

Leave a Comment