In a bash script, I am using rsync to make an exact copy of a directory:

rsync --verbose --archive --update --delete \
    ~/cat-pics/ \

But how can I get feedback on whether or not anything was transferred? How can I know if any files were changed by that operation? In particluar, I wish to know if any files were added, changed, or deleted.

I see the --stats option, but its output seems to be made for humans rather than bash scripts.

Any pointers?

  • While the output of --stats is, as you said, intended for human consumption, it's pretty simple to pull out the data you have an interest in as the output is known. – DopeGhoti Jan 31 at 19:44
  • 1
    There's also --itemize-changes, which might be useful. – Jeff Schaller Jan 31 at 20:33
  • You can also use unison, which is a good tool for synchronizing. There is a text mode version and a GUI version. and I think it will tell you want you want to know. – sudodus Jan 31 at 20:37

Use -i (--itemize-changes) to get output about each file change.

The first character of each output line (in the default format) gives an indication about what happened with the file. And you can modify the format to something that's more relevant for your parsing if necessary.

  • '<' means that a file is being transferred to the remote host (sent).

  • '>' means that a file is being transferred to the local host (received).

  • 'c' means that a local change/creation is occurring for the item (such as the creation of a directory or the changing of a symlink, etc.).

  • 'h' means that the item is a hard link to another item (requires --hard-links).

  • '.' means that the item is not being updated (though it might have attributes that are being modified).

  • '*' means that the rest of the itemized-output area contains a message (e.g. "deleting").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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