Bash – command to show the time elapsed while running a long process

bashcommandosx

Say, if we run some long command, such as a functional test for a website, is there a command such as:

elapsed npm test

where npm test is a process or shell script possibly with several different commands that can take 45 minutes. It'd be nice if during the running, it can print out "22 minutes have elapsed" every minute or every 5 minutes.

The command time can show the total time it takes, but not the time elapsed along the way.

Best Answer

Start the command in the background and poll its elapsed CPU time every minute:

npm test &
while sleep 1m
do
    ps -o etime $!
done
Related Question