• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Linux Time Command

Written by Admin, Updated On December 13, 2020
terminal, time
Linux Time Command

Time command is useful when you want to determine the command execution time. Generally, it’s useful to test the performance of the commands and scripts. In this guide, we will cover how to use the time command in Linux.

When you are writing multiple script which doing same job and want to choose better one by performance, you can use the time command to test the execution time of each script.

Time Command Versions#

The most widely used Linux shells Bash and Zsh have their built-in versions of the time command which is better than the Gnu time command.

Use the type command to determine whether the 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

In Gnu time command, you need to specify the full path /usr/bin/time to the time binary. Use the env command or use a leading backslash \time which prevents both and built-ins from being used.

You can format the output and show other useful information like memory I/O and IPC calls using the Gnu time.

Using Linux Time Command#

Let’s see an example, to measure the time of download the wordpress using the wget tool:

time wget https://wordpress.org/latest.tar.gz

The output is depends on the version of the time command which your system have:

#Bash
real    0m3.565s
user    0m0.042s
sys     0m0.092s


# Zsh
0.042s user 0.092s system 1% cpu 3.565s total


# GNU time (sh)
0.042user 0.092system 0:03.57elapsed 1%CPU (0avgtext+0avgdata 6060maxresident)k
0inputs+201456outputs (0major+315minor)pagefaults 0swaps

Here,

  • The real or total or elapsed is showing the time which taken from start to wget command completed.
  • user – amount of CPU time spent in user mode.
  • system or sys – It shows the amount of CPU time spent in kernel mode.

Conclusion#

You successfully learned how to use the time command. You can learn more about the Gnu time command by visiting the time man page.

If you have any question or feedback, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Redirect stderr to stdout in Bash
Next Article   How to Rename Files and Directories in Linux

Related Posts

  • How to Use sed to Find and Replace String in Files

    How to Use sed to Find and Replace String in Files

    December 18, 2020
  • Linux Head Command

    Linux Head Command

    December 16, 2020
  • Rename Files and Directories in Linux

    How to Rename Files and Directories in Linux

    December 15, 2020

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on Debian 10
    How to Install Python 3.9 on Debian 10 December 25, 2020
  • How to Install Php 8 on Debian 10
    How to Install PHP 8 on Debian 10 January 2, 2021
  • How to Install Python 3.9 on CentOS 8
    How to Install Python 3.9 on CentOS 8 December 31, 2020
  • How to Install Php 8 on Ubuntu 20.04
    How to Install PHP 8 on Ubuntu 20.04 December 28, 2020
  • How to Install GIMP on Debian 10
    How to Install GIMP 2.10 on Debian 10 December 27, 2020
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook