Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I started a hash check of a large file and don't want to restart it using time. How can I get the wall clock time without using time at the beginning or using date right before I invoke a command?

share|improve this question
up vote 7 down vote accepted

For a running process you can do this:

command ps -p "$PID" -o etime
command ps -p "$PID" --no-headers -o etime

As a general feature you can modify your shell prompt. This is my bash prompt definition:

PS1='\nec:$(ec=$?; if [ 0 -eq $ec ];
then printf %-3d $ec;
else echo -n "$TERM_RED_START"; printf %-3d $ec; echo "$TERM_RED_END";
fi) \t  \u@\h:\w\nstart cmd:> '
PS2="cont. cmd:> "

The relevant part for you is the \t for the time.

This does not solve all problems, though. The new prompt will show when the process has ended but the former prompt may have been quite old when the command to be measured was started. So either you remember to renew the prompt before starting long running commands or you have to remember the current time when you want to know how long the current process will have taken.

For a complete solution you need an audit feature (which logs the start and end time of processes). But that may cause a huge amount of data if it cannot be restricted to the shell.

share|improve this answer

Building upon the accepted answer, you can also continuously monitor elapsed time of a running process using watch:

watch command ps -p "$PID" -o etime
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.