So I have a shell script that basicly backs up one server to another server. In the process I have to cp a very large directory (140GB) to another location, in the shell script I would love to have it run a real time stopwatch type counter starting from 0:00 as the files are copying.


EDIT: This is not a progress bar idea :) Just a simple stopwatch timer so you can see how much time is elapsed, rather then the time until the pain is over :)


2 Answers 2


Would using rsync -av --progress instead of cp do what you want?


Just in case David Kings rsync solution doesn't work for you or you do want to do it in bash (why ever), this is how you could do it:

your_command_to_execute &
while kill -0 "$myPid" 2> /dev/null
    # Sleep for the defined time
    sleep $sleepTime
    # And print the time since the script started in seconds
    echo -en "Runtime $SECONDS\033[0K\r"

You might want to use something to format the time a little bit nicer.
Also currently the script prints the seconds since the script started, and not since the cp operation started (if you want to change this simple subtract the seconds before the loop from the current $SECONDS)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .