• 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 Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 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