times

process managementLinux/Unix
The times command is one of the most frequently used commands in Linux/Unix-like operating systems. times Display process time information for the current shell and its children

Quick Reference

Command Name:

times

Category:

process management

Platform:

Linux/Unix

Basic Usage:

times [options] [arguments]

Common Use Cases

    Syntax

    times

    Options

    Option Description
    The times command does not accept any options.

    Examples

    How to Use These Examples

    The examples below show common ways to use the times command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Display time statistics for the current shell times
    # Use times in a script to check process time #!/bin/bash echo "Starting process..." # Do some work for i in {1..1000}; do echo $i > /dev/null done echo "Process stats:" times
    # Advanced Examples Advanced
    # Compare times before and after an operation times # Perform some operation sleep 2 times
    # Use with time command to measure operation duration times time some_command times
    # Redirect times output to a file times > process_times.txt # Use with CPU-intensive operations times # Perform CPU-intensive operation for i in {1..50000}; do echo "Computing..." > /dev/null done times # Compare with /proc/self/stat information times
    cat /proc/self/stat
    # Custom time display in script #!/bin/bash echo "Starting work..." START_TIMES=$(times) # Do some work here sleep 2 END_TIMES=$(times) echo "Started with: $START_TIMES" echo "Ended with: $END_TIMES" # Use in performance monitoring while true; do echo "$(date): $(times)" sleep 10 done

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `times` command is a shell built-in that displays the user and system time used by the shell and its child processes. It's a simple yet useful tool for basic process time accounting within shell scripts and interactive sessions. When executed, `times` outputs four time values (in seconds): 1. **User time for the shell**: CPU time spent executing user instructions within the shell process itself. 2. **System time for the shell**: CPU time spent in kernel mode for the shell process (executing system calls). 3. **User time for children**: Accumulated CPU time spent by all child processes in user mode. 4. **System time for children**: Accumulated CPU time spent by all child processes in kernel mode. These times are reported in the format: ``` 0m0.000s 0m0.000s 0m0.000s 0m0.000s ``` where the first line represents the shell's own times (user and system), and the second line represents the accumulated times for child processes (user and system). Unlike the `time` command, which measures a single command execution, `times` shows the accumulated resource usage since the shell started. This makes it useful for tracking the overall resource usage of shell scripts or interactive sessions over time. The `times` command doesn't accept any arguments or options, making it one of the simplest shell built-ins. Its simplicity, however, is also its limitation - it provides only basic timing information without the detailed metrics available from utilities like `time` or process monitoring tools. It's worth noting that `times` is primarily useful within the context of the current shell session. The accumulated times for child processes reflect only those processes started from the current shell, not system-wide process statistics. Since `times` is a shell built-in command (defined by POSIX), it's available in most Unix-like systems and shells, including bash, sh, ksh, and zsh. However, the exact output format might vary slightly between different shell implementations.

    Related Commands

    These commands are frequently used alongside times or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the times command works in different scenarios.

    $ times
    View All Commands