If I want to time the running of rsync by time rsync -a /media/t/1/ ./, after it finishes, does $? report the exit value for time not for rsync?

How can I both time rsync and get its exit value?

1 Answer 1


Bash's built-in time returns the exit status of the command. You can test that fairly easily with time false; afterwards, echo $? prints 1 as expected. You can also test something with a different exit code to confirm other codes are preserved:

$ time bash -c 'exit 42'; echo "Exit code: $?"

real    0m0.002s
user    0m0.000s
sys     0m0.000s
Exit code: 42

You must log in to answer this question.

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