13

My weekly backup script contains a bunch of bash statements like these:

rsync -va /source_path/ /destination_path/ 

Now, this works great but the -v (verbose) option doesn't behave exactly like I want. What I want is that it should display only the changed files which are being copied, and not each and every folder it scans.

For example, if document1 and document2 folders are unchanged, but a file is changed in document3, then the display will be as follows:

document1/ document2/ document3/ document3/foo.txt 

If I omit the -v option altogether, its totally silent and doesn't display anything at all. I want the output display but I'm only interested in the last line (foo.txt) which is the file being copied, not the dozens of folders which rsync scans such as document1, document2, etc.

Is there any way to do it?

2
  • That's already how rsync works. It's listing those directories because it thinks they're not in sync. Please run with the -i flag and include the output in your question. Commented Mar 25, 2019 at 15:53
  • 1
    The directories might be getting sync'd just to update their timestamp. Use -i to see exactly why they being synced. You might try -c (checksum) or --size-only, or just filter them out with | egrep -v '/$' Commented Apr 2, 2019 at 3:25

2 Answers 2

13

Your description is already how rsync works. The only files it displays with -v are ones that it is either transferring or changing. So each time it runs, it sees there is some difference with the directories.

A common reason for this is that the source and destination are on different filesystems and the ownership or permissions can't be copied exactly, and each invocation is trying to do so.

To confirm this, run the rsync with -i (or --itemize-changes). This will display a code that shows the reason rsync has decided the file needs work. If its an ownership or something (and you decide you don't need this information), you can turn off the syncing of it with --no-owner or similar.

3
  • This worked for me, thanks @BowlOfRed. My source hard drive was using the EXT4 file system, and destination hard drive was using NFTS, so I kept getting those pointless directory listings described in the question above even though no files within those directories were being modified. Simply reformatting my destination drive to use EXT4 solved the problem. Commented Jun 10, 2020 at 8:44
  • 5
    It would be better to use --omit-dir-times (-O), if it's the timestamps on the directories that are the issue. That way you don't really affect the way non-directories are synchronized. Commented Jul 16, 2021 at 7:36
  • 1
    In my personal case (rsync from ext4 to ntfs), I would rather use --no-perms, since the -i flag raised the p update, as in .d...p..... for all directories and .f...p..... for all files. Commented Sep 22, 2024 at 19:21
1

You can only display changed files instead of folders using grep.

rsync -va /source_path/ /destination_path/ | grep -v '/$' 

This will only display:

document3/foo.txt 

You can further improve readability by splitting the files that have changed using = and removing unwanted output:

rsync -va /source_path/ /destination_path/ | grep -v '/$' | sed '/^sending incremental file list/i\========================================' | grep -v '^sending incremental file list' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.