# Timing Your Shell Commands Using The Time Command In Linux

> Check out our guide to understand what the time command is, how to use it, and how to understand the resulting output.

- Author: [CJ Saathoff](https://www.namehero.com/blog/author/cj-saathoff/)
- Published: 2024-05-22
- Updated: 2024-05-22
- Category: [Linux Command Line](https://www.namehero.com/blog/category/linux-command-line/)
- Web page: https://www.namehero.com/blog/timing-your-shell-commands-using-the-time-command-in-linux/

[![](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/04/10161744/timingyour-1024x576.jpg)](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/04/10161744/timingyour.jpg)

Have you ever thought it would be nice to time a command? Do you end up taking out a stopwatch or your smartphone? I have good news… Linux has a command for that, the time command. The time command in Linux gives you the option to time command from the very shell you run the command from.

## What Is The Linux Time Command?

Have you ever thought it would be nice to time a command? Do you end up taking out a stopwatch or your smartphone? The time command in Linux is used to measure command execution time from the very shell you run the command from.

## How Do I Get The Time Command?

On most Linux distributions the time command is pre-installed. If you find it isn’t preinstalled try searching for the package by the name of your package manager. If neither of these works please refer to your Linux Distributions documentation.

Be aware both Bash and Zsh have built-in versions of the time command. These are both separate from the Upstream GNU version provided by the free software foundation.

## Usage

Ok, so you have a command you want to time, for example, it could be that a command is taking a while, or could be as simple as wanting to have numbers on how long a command takes.

To measure execution time for a command replace command in the following command:

```

time command

```

Note: The GNU version of the time command has many flags that can be used but is not universal compared to other versions of the time command. If you find yourself using GNU time be aware it is not universal and refer to the [man page](https://man.archlinux.org/man/time.1) for flags.

## Understanding the output

Below is the output you will get from the basic syntax.

>

real 0m0.000s

user 0m0.000s

sys 0m0.000s

The descriptions below explain what is being measured for each.

real – The Real-time is the execution time of the command from start to finish.

user – The user time is the CPU time spent executing system time.

sys – The system time is the time spent on system calls and the like.

## Examples

Time the time it takes to recursively copy from one directory to another

```

time cp -r /source/directory /destination/directory

```

Time a script

```

time ./script.sh

```

Time and output the results of the ls command to a file

```

time ls > output.txt 2>&amp;1

```

Time with a shell pipe

```

time (command1 | command2)

```

Time a MySQL query

```

time mysql -u username -p -e "SELECT * FROM table_name"

```

## Conclusion

The time command is rather simple but simple isn’t a bad thing, as even the simplest Linux commands can be priceless. In this blog post, we have discussed what the time command is, that it should be available on almost all Linux distributions by default, how to use the command, and how to understand the resulting output. Finally ending on some examples of how you can use the time command with various other commands.

## Additional Links

Want to read more about other Linux Commands check out our other posts.

- [Other Linux Command Posts](https://www.namehero.com/blog/category/linux-command-line/)

## Related posts

- [Differentiating the df vs du Commands in Linux](https://www.namehero.com/blog/differentiating-the-df-vs-du-commands-in-linux/)
- [How to Use the Tee Command in Linux](https://www.namehero.com/blog/how-to-use-the-tee-command-in-linux/)
- [How to Use the xargs Command in Linux](https://www.namehero.com/blog/how-to-use-the-xargs-command-in-linux/)
- [Understanding The Mv Command In Linux](https://www.namehero.com/blog/understanding-the-mv-command-in-linux/)
