How to output a list of changed files from rsync?
Solution 1:
You can use rsync's --itemize-changes
(-i
) option to generate a parsable output that looks like this:
~ $ rsync src/ dest/ -ai
.d..t.... ./
>f+++++++ newfile
>f..t.... oldfile
~ $ echo 'new stuff' > src/newfile
~ $ !rsync
rsync src/ dest/ -ai
>f.st.... newfile
The >
character in the first position indicates a file was updated, the remaining characters indicate why, for example here s
and t
indicate that the file size and timestamp changed.
A quick and dirty way to get the file list might be:
rsync -ai src/ dest/ | egrep '^>'
Obviously more advanced parsing could produce cleaner output :-)
I came across this great link while trying to find out when --itemize-changes
was introduced, very useful:
http://andreafrancia.it/2010/03/understanding-the-output-of-rsync-itemize-changes.html (archived link)
Solution 2:
Use the -n
flag, combined with the -c
checksum flag and the -i
flag:
# rsync -naic test/ test-clone/
>fcst...... a.txt
>fcst...... abcde.txt
>fcst...... b.txt
In this example, three files have changed, based on the contents (as determined by the checksum) of the file itself. However, no file syncing is done because of the -n
flag
Bonus
If you want to run chown on the changed files, parse them out with sed
or similar and process with xargs, for example:
rsync -naic test/ test-clone/ | sed 's/............//' | xargs -I+ sudo chown root "test-clone/+"
Solution 3:
This question is a little bit old, but I think it worth to be added:
-i
is a shortcut of --out-format=%i%n%L
And %n
means the filename, (section log format
of man rsyncd.conf
)
P.S. rsync version 3.1.0