Unix / Linux: Shell Stopwatch

Objective: Time an event or something using the shell on Unix or Linux.

The time command can be used to time any events. Use one of the following commands to start the timer.

The time command will keep the time and will print the elapsed time when the program (we are using the commands read, cat and dd) passed to it exits. Since the commands are waiting for a user input, we have the flexibility to determine when to stop the timer – by giving the required user input to end the commands.

To stop the timer and get the elapsed time, press the enter key for the first command syntax (using time read). For the remaining commands, press Ctrl-C and you will be given the elapsed time. An example of the output is shown below.

If you need to keep track of time at specific intervals, you can use the dd command. Start the timer by running dd.

Whenever you need the elapsed time, send USR1 signal to the dd process using another terminal.

This will inform the dd process to print out the statistics, one of them being the time in seconds. The output will be similar to the one found below. The USR1 signal was sent at around 2.75 and 10.19 seconds.

To stop the timer and end the dd process, press Ctrl-C in the terminal running the dd process.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }