time
Displays or sets the system time. If used without parameters, time displays the current system time and prompts you to enter a new time.
Note
You must be an administrator to change the current time.
Syntax
time [/t | [<HH>[:<MM>[:<SS>]] [am|pm]]]
Parameters
Parameter | Description |
---|---|
<HH>[:<MM>[:<SS>[.<NN>]]] [am | pm] |
Sets the system time to the new time specified, where HH is in hours (required), MM is in minutes, and SS is in seconds. NN can be used to specify hundredths of a second. You must separate values for HH, MM, and SS with colons (:). SS and NN must be separated with a period (.).If am or pm isn’t specified, time uses the 24-hour format by default. |
/t | Displays the current time without prompting you for a new time. |
/? | Displays help at the command prompt. |
Remarks
- Valid HH values are 0 through 24.
- Valid MM and SS values are 0 through 59.
Examples
If command extensions are enabled, to display the current system time, type:
time /t
To change the current system time to 5:30 PM, type either of the following:
time 17:30:00
time 5:30 pm
To display the current system time, followed by a prompt to enter a new time, type:
The current time is: 17:33:31.35
Enter the new time:
To keep the current time and return to the command prompt, press ENTER. To change the current time, type the new time and then press ENTER.
Linux time command
The time command is used to determine how long a given command takes to run. It is useful for testing the performance of your scripts and commands.
For example, if you have two different scripts doing the same job and you want to know which one performs better you can use the Linux time command to determine the duration of execution of each script.
Time Command Versions
Both Bash and Zsh, the most widely used Linux shells have their own built-in versions of the time command which take precedence over the Gnu time command.
You can use the type
command to determine whether time is a binary or a built-in keyword.
type time
# Bash
time is a shell keyword
# Zsh
time is a reserved word
# GNU time (sh)
time is /usr/bin/time
To use the Gnu time command, you need to specify the full path to the time binary, usually /usr/bin/time
, use the env
command or use a leading backslash \time
which prevents both and built-ins from being used.
The Gnu time allows you to format the output and provides other useful information like memory I/O and IPC calls.
Using Linux Time Command
In the following example, we are going to measure the time taken to download the Linux kernel using the wget tool :
time wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.19.9.tar.xz
What will be printed as an output depends on the version of the time command you’re using:
# Bash
real 0m33.961s
user 0m0.340s
sys 0m0.940s
# Zsh
0.34s user 0.94s system 4% cpu 33.961 total
# GNU time (sh)
0.34user 0.94system 0:33.96elapsed 4%CPU (0avgtext+0avgdata 6060maxresident)k
0inputs+201456outputs (0major+315minor)pagefaults 0swaps
- real or total or elapsed (wall clock time) is the time from start to finish of the call. It is the time from the moment you hit the
Enter
key until the moment thewget
command is completed. - user – amount of CPU time spent in user mode.
- system or sys – amount of CPU time spent in kernel mode.