19

I have a problem with rsync: either it shows me all files in the directories I am rsyncing (if using the flag -v) or nothing at all (when not using -v).

I would like to have rsync quiet except for the files which actually had to be uploaded to the far end. Is there a flag to activate this kind of reporting? I can not find this in the documentation

6 Answers 6

15

Yes, check out the -i flag. It gives a report of every operation in a cryptic format. See the man page for the exact definition of the format.

In order to get the list of files which are sent to the remote host, you could use the following:

rsync <options> -i <src> <dst> | grep '^<' | awk '{ print $2 }'
11
  • 1
    This is reporting again all files, not the changed ones.
    – blueFast
    Jun 22, 2012 at 7:33
  • @gonvaled No, only the files which are sent to the remote host are output (as <fcstpoguax filename, where the different flags show why they need to be updated). If it reports all files, something may be wrong with your test or your environment.
    – Oliver
    Jun 22, 2012 at 7:41
  • I think you are right. I have taken a look at the manpage and it is described as you say. But my system is reporting all files. Maybe something wrong with the far-end ...
    – blueFast
    Jun 22, 2012 at 7:43
  • Mmmm. getting closer: the reporting string is (for all files) <f..T....... According to the manpage, this is related to timestamps.
    – blueFast
    Jun 22, 2012 at 7:48
  • 3
    using grep -E '^[^.]|^$' would also let statistic (or warnings, errors,...) lines through, only removing the really boring lines starting with a dot...
    – Frank N
    Feb 26, 2017 at 11:47
12

rsync with a single -v|--verbose actually prints only transferred files (as well as a header/footer). If you are getting the complete list every time then it probably means that the default rsync src/dest comparison algorithm, which is based on modification time + size, is not suitable for your case. You may add the -c (--checksum) flag which makes rsync compare files by checksumming. Note that this obviously incurs some I/O overhead.

Slightly related is the fact that if you use --info=flist instead of -v then you get a more trimmed output of the files (you basically skip the header and footer of the typical -v output).

3
  • 1
    --info=flist is only available in rsync >= 3.1, which is not available everywhere. For example macOS is delivered with an ancient version 2.6.9 because Rsync v3 is unter GPL 3.
    – chiborg
    Jun 12, 2017 at 20:44
  • 1
    While that Apple GPL rumour is super-juicy, also remember that Enterprise Linux has a massive support range (14 years) where versions are locked (and branched) to preserve certification and guarantee compatibility (api+abi) over the supported life of the release. It's actually the only feasible way of doing that, and the side effect is that version numbers appear old and new features don't hit the Enterprise for what may seem like a Long time. Aug 15, 2018 at 19:17
  • 1
    I believe the --info=flist flag may have changed. --info=name gives me the output expected onrsync 3.1.3
    – CervEd
    Sep 27, 2021 at 8:12
3

1. Use the -i option

For these iconized (or: cryptic) change flags. You output will look like this:

*deleting   DSC00012 (copy).JPG
.d..tp..... ./
.f...p..... DSC00011.JPG
>f+++++++++ DSC00012 (copy2).JPG
>f.stp..... DSC00012.JPG
.f...p..... DSC00014.JPG

Number of files: 5 (reg: 4, dir: 1)
Number of created files: 1 (reg: 1)
... more statistic stuff
sent 636.01K bytes  received 4.63K bytes  1.28M bytes/sec
total size is 2.84M  speedup is 4.44

2. grep every line starting with a dot.

Let all other lines (also blank ones, for legibility) pass:

rsync -arz -i --stats -h ... /mnt/FooDrive/ /mnt/backup  | grep -E '^[^.]|^$'

And here we are :-) — Just what the doctor ordered:

*deleting   DSC00012 (copy2).JPG
>f.stp..... DSC00011.JPG
>f+++++++++ DSC00012 (copy).JPG

Number of files: 5 (reg: 4, dir: 1)
Number of created files: 1 (reg: 1)
...

Avoiding dots rather than hunting for > has the benefit to also let statistics, but also potential errors, warnings etc pass through...

Having stats at the end is a personal preference. Don't use -h --stats if you don't like these. I assume your key interest is in not seeing hundred or thousands of unchanged files scroll by...

1
  • what does .d...p...... mean in front of each file?
    – seralouk
    Dec 8, 2022 at 13:08
2

one thing that comes to my mind is using more verbose log format and awk'ing out what you want to get.

eg:

rsync -a --out-format="%b  %i %f" /etc/ /tmp/qq/ |awk '{if ($1>0) {print $3}}'

this is not very robust, it'll not handle well file-names with spaces.

1

I don't think there is a flag to do this but there might be now. Here was the way I did it:

rsync -vv [other options] | grep -v 'uptodate'
2
  • 1
    My rsync (version 3.0.7) does not add uptodate to the reporting, so not possible to filter that out.
    – blueFast
    Jun 22, 2012 at 7:37
  • I want to correct, or at least clarify, what Mike posted above and what @jeckyll2hide pointed out. I think the issue is not that rsync -v no longer emits the string "uptodate" but rather that you need to use rsync -vv. Note the two vs. I just verified this works on Ubuntu 14.04 with rsync version 3.1.0. Mike, can you update your post to reflect this? Apr 27, 2016 at 3:51
0
rsync -av --delete-before --force --progress /path/to/src/dir/ -e ssh user@host:/path/to/target/dir | grep -v '.*\/$'

This works for me ("rsync version 3.1.3 protocol version 31" on src machine and "rsync version 3.1.2 protocol version 31" on target machine to be exact). It simply omits any lines with trailing slash, which are the main portion of unchanged stuff just scrolling by needlessly. grep -v inverts the search pattern, so only non-matching lines are output. Have been searching for this for ages, finally got around to figuring it out. Hope it is useful to you!

Correction: There needs to be a backslash before the slash in the grep expression for it to work the way it should, added it

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