Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 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 at 0:18

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.