1

I'm trying to make the terminal always display the execution time of a process that I call via the command line (i.e., I want to find out how long it takes to for the process to finish).

I know that if you type time before the command, at the end it will display the execution time, but the idea is not to type anything but the command and receive the execution time at the end if possible.

Luis
  • 11
  • 1
  • 1
    Perhaps this will be helpful: [How can I automatically time commands in bash?](https://askubuntu.com/questions/205974/how-can-i-automatically-time-commands-in-bash) – steeldriver Oct 17 '21 at 21:02

2 Answers2

0

Use tcsh and set time

A very easy method to time each command is to install and use the shell tcsh (instead of bash which is standard in Ubuntu) and set the variable time,

tester@my-laptop:~$ sudo apt install tcsh

tester@my-laptop:~$ tcsh
my-laptop:~> set time
my-laptop:~> sleep 3
0.003u 0.000s 0:03.00 0.0%      0+0k 0+0io 0pf+0w
my-laptop:~> 

Show the wall-time when each prompt was printed in bash

Maybe it would be enough for you to have a clock in the prompt, so that you see the 'wall-time' when the command finished and the terminal window returned to prompt?

A crude prompt to enter interactively for this purpose would be

PS1='$(date '+%T') $ '

or to add to the current prompt

PS1='$(date '+%T') '"$PS1"

Reset to the standard prompt with

source ~/.bashrc
sudodus
  • 45,126
  • 5
  • 87
  • 151
-2

run the command with time(which is a shell keyword aka a command) like this. time foobar or time sleep 1. anorthor example is

#!/bin/bash
#how big is your file system
time tree /
lnee
  • 796
  • 4
  • 21