Server Fault is a question and answer site for system and network administrators. 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've got a bash script that rsync's two directories. Sometimes there's a change, odds are there's nothing.

I want to run a command only if rsync actually made a change (add/update a file). Otherwise I want to just skip it. Is there a return response I should be looking at?

share|improve this question
up vote 7 down vote accepted

If you use the -i option (and don't use the -v option), rsync will only print lines to STDOUT for any changes that were made. Depending on your script, this could look like

if [ -n "$(rsync -i /dir1 /dir2)" ]; then
share|improve this answer
That seems to do exactly what I want... thanks. Didn't think of using the -i flag like that. – raccettura Jun 30 '10 at 16:51
To clarify, if you want to run the script only if a change was made, then == should be !=. – hamx0r Mar 3 '15 at 0:18
Well as it is, this code is wrong from what I have seen. As for that code you get it Rsync ran FINE or HAS ERROR running, but this code doesn't check if there was a change. I don´t know if other version of Rsync could that, but I´m using RSYNC in Raspbmc (an old implementation we have) and OSMC. This is sad as RSYNC seems to be a wonderful tool. – user321233 Nov 9 '15 at 15:38

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.